nginx.conf 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. server {
  2. #服務部屬上Container用的是哪個Port
  3. listen 80;
  4. server_name localhost;
  5. client_max_body_size 2000M;
  6. client_body_buffer_size 128k;
  7. proxy_connect_timeout 5;
  8. proxy_send_timeout 1800;
  9. proxy_read_timeout 1800;
  10. proxy_buffer_size 4k;
  11. proxy_buffers 4 32k;
  12. proxy_busy_buffers_size 64k;
  13. proxy_temp_file_write_size 64k;
  14. auth_basic "status";
  15. #開啟gzip
  16. gzip on;
  17. #低於1kb的資源不壓縮
  18. gzip_min_length 1k;
  19. #壓縮級別1-9,越大壓縮率越高,同時消耗cpu資源也越多,建議設置在5左右。
  20. gzip_comp_level 5;
  21. #需要壓縮哪些response類型的資源,用空格隔開。不建議壓縮圖片.
  22. gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
  23. #配置禁用gzip條件,支持正規表達式。此處表示ie6及以下不啟用gzip
  24. gzip_disable "MSIE [1-6]\.";
  25. #是否添加"Vary: Accept-Encoding" response header
  26. gzip_vary on;
  27. #location / 是指當從外部訪問這個服務的時候,他需要帶什麼路徑 (這邊寫是localhost:7777/)
  28. #如果希望是訪問的網址是 localhost:7777/myWeb 就寫成location /myWeb
  29. # location /admin {
  30. # root /usr/share/nginx/html/admin;
  31. # index index.html index.htm;
  32. # try_files $uri $uri/ /index.html;
  33. # }
  34. location / {
  35. root /usr/share/nginx/html;
  36. index index.html index.htm;
  37. try_files $uri $uri/ /index.html;
  38. }
  39. # 二级目录配置(/subdir)
  40. location /admin {
  41. alias /usr/share/nginx/html/admin; # 子应用的静态文件目录
  42. index index.html;
  43. client_max_body_size 2000M;
  44. try_files $uri $uri/ /admin/index.html;
  45. }
  46. # # 防止二级目录下的静态资源被错误处理
  47. location /admin/ {
  48. alias /usr/share/nginx/html/admin/;
  49. try_files $uri $uri/ =404;
  50. }
  51. # # 配置静态资源缓存
  52. # location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  53. # expires 1y;
  54. # add_header Cache-Control "public";
  55. # }
  56. # 代理 API 请求到后端服务
  57. location /api/ {
  58. proxy_pass http://backend:8085/; # 后端 API 地址
  59. proxy_set_header Host $host;
  60. proxy_set_header X-Real-IP $remote_addr;
  61. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  62. proxy_set_header X-Forwarded-Proto $scheme;
  63. client_max_body_size 2000M;
  64. # 如果需要支持 WebSocket,添加以下配置
  65. proxy_http_version 1.1;
  66. proxy_set_header Upgrade $http_upgrade;
  67. proxy_set_header Connection "upgrade";
  68. }
  69. error_page 500 502 503 504 /50x.html;
  70. location = /50x.html {
  71. root /usr/share/nginx/html;
  72. }
  73. }