nginx.conf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Nginx配置示例 - 工资发放管理系统
  2. # 文件位置: /etc/nginx/conf.d/payroll.conf 或 /etc/nginx/sites-available/payroll
  3. server {
  4. listen 80;
  5. server_name your-domain.com; # 修改为您的域名或IP
  6. # 访问日志
  7. access_log /var/log/nginx/payroll_access.log;
  8. error_log /var/log/nginx/payroll_error.log;
  9. # 前端静态文件
  10. root /var/www/payroll-web;
  11. index index.html;
  12. # 前端路由配置 - Vue Router history模式
  13. location / {
  14. try_files $uri $uri/ /index.html;
  15. # 设置缓存
  16. expires 7d;
  17. add_header Cache-Control "public, immutable";
  18. }
  19. # API接口代理到后端
  20. location /api/ {
  21. proxy_pass http://localhost:8080/api/;
  22. # 代理头设置
  23. proxy_set_header Host $host;
  24. proxy_set_header X-Real-IP $remote_addr;
  25. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  26. proxy_set_header X-Forwarded-Proto $scheme;
  27. # 超时设置
  28. proxy_connect_timeout 60s;
  29. proxy_send_timeout 60s;
  30. proxy_read_timeout 60s;
  31. # 缓冲设置
  32. proxy_buffering on;
  33. proxy_buffer_size 8k;
  34. proxy_buffers 8 8k;
  35. # 禁用缓存(API接口)
  36. add_header Cache-Control "no-cache, no-store, must-revalidate";
  37. }
  38. # 静态资源缓存优化
  39. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  40. expires 30d;
  41. add_header Cache-Control "public, immutable";
  42. }
  43. # Gzip压缩
  44. gzip on;
  45. gzip_vary on;
  46. gzip_proxied any;
  47. gzip_comp_level 6;
  48. gzip_types text/plain text/css text/xml text/javascript
  49. application/json application/javascript application/xml+rss
  50. application/rss+xml font/truetype font/opentype
  51. application/vnd.ms-fontobject image/svg+xml;
  52. }
  53. # HTTPS配置示例(推荐生产环境使用)
  54. # server {
  55. # listen 443 ssl http2;
  56. # server_name your-domain.com;
  57. #
  58. # # SSL证书配置
  59. # ssl_certificate /path/to/your/cert.pem;
  60. # ssl_certificate_key /path/to/your/key.pem;
  61. #
  62. # # SSL安全设置
  63. # ssl_protocols TLSv1.2 TLSv1.3;
  64. # ssl_ciphers HIGH:!aNULL:!MD5;
  65. # ssl_prefer_server_ciphers on;
  66. #
  67. # # 其他配置同上...
  68. # root /var/www/payroll-web;
  69. # index index.html;
  70. #
  71. # location / {
  72. # try_files $uri $uri/ /index.html;
  73. # }
  74. #
  75. # location /api/ {
  76. # proxy_pass http://localhost:8080/api/;
  77. # proxy_set_header Host $host;
  78. # proxy_set_header X-Real-IP $remote_addr;
  79. # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  80. # proxy_set_header X-Forwarded-Proto $scheme;
  81. # }
  82. # }
  83. # HTTP跳转到HTTPS
  84. # server {
  85. # listen 80;
  86. # server_name your-domain.com;
  87. # return 301 https://$server_name$request_uri;
  88. # }