nginx.conf 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. access_log /data/logs/customs/tsf-access.log main;
  2. error_log /data/logs/customs/tsf-error.log notice;
  3. gzip_static on;
  4. gzip on;
  5. gzip_proxied expired no-cache no-store private auth; #启用压缩的响应头
  6. gzip_min_length 1k; #文件大于1k压缩
  7. gzip_buffers 4 16k; #设置压缩所需要的缓冲区大小
  8. gzip_http_version 1.1; #http协议版本
  9. gzip_comp_level 2; #压缩级别 1-9
  10. gzip_types text/plain application/javascript text/css #文件类型
  11. gzip_vary on; #是否在http header 中添加 Vary: Accept-Encoding 建议开启
  12. server {
  13. listen 8080;
  14. # html类 不缓存
  15. location ~ \.(html|htm)$ {
  16. root /usr/share/nginx/html;
  17. add_header Cache-Control no-cache;
  18. }
  19. # css、js 缓存,仅客户端缓存
  20. location ~ \.(css|js)$ {
  21. root /usr/share/nginx/html;
  22. add_header Cache-Control private,max-age=28800;
  23. }
  24. # 图片类 缓存,仅客户端缓存
  25. location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {
  26. root /usr/share/nginx/html;
  27. add_header Cache-Control private,max-age=28800;
  28. }
  29. # 字体类 缓存,仅客户端缓存
  30. location ~ \.(ttf|woff|woff2|otf|ttc|eot|svg)$ {
  31. root /usr/share/nginx/html;
  32. add_header Cache-Control private,max-age=28800;
  33. }
  34. location / {
  35. try_files $uri $uri/ @router;
  36. root /usr/share/nginx/html;
  37. index index.html index.htm;
  38. }
  39. location /api/ {
  40. proxy_set_header Host $host;
  41. proxy_set_header X-Real-IP $remote_addr;
  42. proxy_set_header X-Forwarded-for $remote_addr;
  43. proxy_connect_timeout 300;
  44. port_in_redirect off;
  45. rewrite ^/api/(.*) /$1 break;
  46. proxy_pass http://apigw:11000/;
  47. }
  48. location /static-resource/ {
  49. proxy_set_header Host $host;
  50. proxy_set_header X-Real-IP $remote_addr;
  51. proxy_set_header X-Forwarded-for $remote_addr;
  52. proxy_connect_timeout 300;
  53. port_in_redirect off;
  54. rewrite ^/static-resource/(.*) /$1 break;
  55. proxy_pass http://static-resource-web:8080/;
  56. }
  57. location @router {
  58. rewrite ^.*$ /index.html last;
  59. }
  60. }