nginx-dibang.conf 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. server {
  2. listen 8011;
  3. # Web 前端域名
  4. server_name 121.43.228.102;
  5. # HTTPS 配置(取消注释并配置 SSL 证书后启用)
  6. # listen 443 ssl http2;
  7. # ssl_certificate /path/to/ssl/cert.pem;
  8. # ssl_certificate_key /path/to/ssl/key.pem;
  9. # ssl_protocols TLSv1.2 TLSv1.3;
  10. # ssl_ciphers HIGH:!aNULL:!MD5;
  11. # ssl_prefer_server_ciphers on;
  12. # 日志配置
  13. access_log /var/log/nginx/dibang-web-access.log;
  14. error_log /var/log/nginx/dibang-web-error.log;
  15. # Web 前端根目录
  16. root /iflytek/dibang/web;
  17. index index.html;
  18. # 字符集
  19. charset utf-8;
  20. # 前端静态文件 - SPA 路由支持
  21. location / {
  22. try_files $uri $uri/ /index.html;
  23. add_header Cache-Control "no-cache, no-store, must-revalidate";
  24. add_header Pragma "no-cache";
  25. add_header Expires "0";
  26. }
  27. # 静态资源缓存(JS、CSS、图片等)
  28. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp)$ {
  29. expires 1y;
  30. add_header Cache-Control "public, immutable";
  31. access_log off;
  32. }
  33. # API 代理到后端服务
  34. location /api {
  35. proxy_pass http://127.0.0.1:8000;
  36. proxy_http_version 1.1;
  37. # WebSocket 支持
  38. proxy_set_header Upgrade $http_upgrade;
  39. proxy_set_header Connection "upgrade";
  40. # 请求头(包含端口信息,确保前端能获取到正确的端口)
  41. proxy_set_header Host $host:$server_port;
  42. proxy_set_header X-Real-IP $remote_addr;
  43. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  44. proxy_set_header X-Forwarded-Proto $scheme;
  45. proxy_set_header X-Forwarded-Host $host;
  46. proxy_set_header X-Forwarded-Port $server_port;
  47. # 超时设置
  48. proxy_connect_timeout 60s;
  49. proxy_send_timeout 60s;
  50. proxy_read_timeout 60s;
  51. # 缓冲设置(关闭缓冲以支持流式响应)
  52. proxy_buffering off;
  53. proxy_request_buffering off;
  54. # 错误处理
  55. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  56. }
  57. # 健康检查端点
  58. location /health {
  59. proxy_pass http://127.0.0.1:8000/;
  60. proxy_set_header Host $host:$server_port;
  61. access_log off;
  62. }
  63. # 禁止访问隐藏文件
  64. location ~ /\. {
  65. deny all;
  66. access_log off;
  67. log_not_found off;
  68. }
  69. }
  70. # ============================================
  71. # H5 移动端配置(域名访问)
  72. # ============================================
  73. server {
  74. listen 8012;
  75. # H5 移动端域名和 IP(IP 直接访问时显示 H5)
  76. server_name 121.43.228.102;
  77. # HTTPS 配置(取消注释并配置 SSL 证书后启用)
  78. # listen 443 ssl http2;
  79. # ssl_certificate /path/to/ssl/cert.pem;
  80. # ssl_certificate_key /path/to/ssl/key.pem;
  81. # ssl_protocols TLSv1.2 TLSv1.3;
  82. # ssl_ciphers HIGH:!aNULL:!MD5;
  83. # ssl_prefer_server_ciphers on;
  84. # 日志配置
  85. access_log /var/log/nginx/dibang-h5-access.log;
  86. error_log /var/log/nginx/dibang-h5-error.log;
  87. # H5 前端根目录
  88. root /iflytek/dibang/app;
  89. index index.html;
  90. # 字符集
  91. charset utf-8;
  92. # 前端静态文件 - SPA 路由支持
  93. location / {
  94. try_files $uri $uri/ /index.html;
  95. add_header Cache-Control "no-cache, no-store, must-revalidate";
  96. add_header Pragma "no-cache";
  97. add_header Expires "0";
  98. }
  99. # 静态资源缓存(JS、CSS、图片等)
  100. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp)$ {
  101. expires 1y;
  102. add_header Cache-Control "public, immutable";
  103. access_log off;
  104. }
  105. # API 代理到后端服务
  106. location /api {
  107. proxy_pass http://127.0.0.1:8000;
  108. proxy_http_version 1.1;
  109. # WebSocket 支持
  110. proxy_set_header Upgrade $http_upgrade;
  111. proxy_set_header Connection "upgrade";
  112. # 请求头(包含端口信息,确保前端能获取到正确的端口)
  113. proxy_set_header Host $host:$server_port;
  114. proxy_set_header X-Real-IP $remote_addr;
  115. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  116. proxy_set_header X-Forwarded-Proto $scheme;
  117. proxy_set_header X-Forwarded-Host $host;
  118. proxy_set_header X-Forwarded-Port $server_port;
  119. # 超时设置
  120. proxy_connect_timeout 60s;
  121. proxy_send_timeout 60s;
  122. proxy_read_timeout 60s;
  123. # 缓冲设置(关闭缓冲以支持流式响应)
  124. proxy_buffering off;
  125. proxy_request_buffering off;
  126. # 错误处理
  127. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  128. }
  129. # 健康检查端点
  130. location /health {
  131. proxy_pass http://127.0.0.1:8000/;
  132. proxy_set_header Host $host:$server_port;
  133. access_log off;
  134. }
  135. # 禁止访问隐藏文件
  136. location ~ /\. {
  137. deny all;
  138. access_log off;
  139. log_not_found off;
  140. }
  141. }