nginx.conf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # 面试管理系统 Nginx 配置模板
  2. server {
  3. # 监听端口
  4. listen 80;
  5. # 域名配置(请替换为您的域名)
  6. server_name yourdomain.com www.yourdomain.com;
  7. # 网站根目录(请替换为实际路径)
  8. root /var/www/interview_web;
  9. index index.html;
  10. # 字符集设置
  11. charset utf-8;
  12. # 日志设置
  13. access_log /var/log/nginx/interview_web.access.log;
  14. error_log /var/log/nginx/interview_web.error.log;
  15. # Gzip 压缩配置
  16. gzip on;
  17. gzip_vary on;
  18. gzip_min_length 1024;
  19. gzip_comp_level 6;
  20. gzip_types text/plain text/css text/xml text/javascript
  21. application/json application/javascript application/xml+rss
  22. application/rss+xml font/truetype font/opentype
  23. application/vnd.ms-fontobject image/svg+xml;
  24. # Vue Router 历史模式支持
  25. location / {
  26. try_files $uri $uri/ /index.html;
  27. }
  28. # API 代理配置
  29. location /api {
  30. # 后端服务地址(请修改为实际后端地址)
  31. proxy_pass http://127.0.0.1:8000;
  32. # 代理头设置
  33. proxy_set_header Host $host;
  34. proxy_set_header X-Real-IP $remote_addr;
  35. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  36. proxy_set_header X-Forwarded-Proto $scheme;
  37. # 超时设置
  38. proxy_connect_timeout 300;
  39. proxy_send_timeout 300;
  40. proxy_read_timeout 300;
  41. # 缓冲设置
  42. proxy_buffering on;
  43. proxy_buffer_size 4k;
  44. proxy_buffers 8 4k;
  45. proxy_busy_buffers_size 8k;
  46. # 不代理错误到客户端
  47. proxy_intercept_errors on;
  48. }
  49. # 静态资源缓存配置
  50. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  51. expires 1y;
  52. add_header Cache-Control "public, immutable";
  53. # 启用 CORS(如果需要)
  54. add_header 'Access-Control-Allow-Origin' '*' always;
  55. add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
  56. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
  57. }
  58. # 禁止访问隐藏文件
  59. location ~ /\. {
  60. deny all;
  61. access_log off;
  62. log_not_found off;
  63. }
  64. # 禁止访问特定文件
  65. location ~* \.(git|svn|htaccess|htpasswd) {
  66. deny all;
  67. }
  68. # 安全头设置
  69. add_header X-Frame-Options "SAMEORIGIN" always;
  70. add_header X-Content-Type-Options "nosniff" always;
  71. add_header X-XSS-Protection "1; mode=block" always;
  72. # SSL 配置(启用 HTTPS 时取消注释)
  73. # listen 443 ssl http2;
  74. # ssl_certificate /path/to/cert.pem;
  75. # ssl_certificate_key /path/to/key.pem;
  76. # ssl_protocols TLSv1.2 TLSv1.3;
  77. # ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
  78. # ssl_prefer_server_ciphers on;
  79. # ssl_session_cache shared:SSL:10m;
  80. # ssl_session_timeout 10m;
  81. }
  82. # HTTP 重定向到 HTTPS(启用 HTTPS 时取消注释)
  83. # server {
  84. # listen 80;
  85. # server_name yourdomain.com www.yourdomain.com;
  86. # return 301 https://$server_name$request_uri;
  87. # }