| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- # 面试管理系统 Nginx 配置模板
- server {
- # 监听端口
- listen 80;
- # 域名配置(请替换为您的域名)
- server_name yourdomain.com www.yourdomain.com;
-
- # 网站根目录(请替换为实际路径)
- root /var/www/interview_web;
- index index.html;
- # 字符集设置
- charset utf-8;
- # 日志设置
- access_log /var/log/nginx/interview_web.access.log;
- error_log /var/log/nginx/interview_web.error.log;
- # Gzip 压缩配置
- gzip on;
- gzip_vary on;
- gzip_min_length 1024;
- gzip_comp_level 6;
- gzip_types text/plain text/css text/xml text/javascript
- application/json application/javascript application/xml+rss
- application/rss+xml font/truetype font/opentype
- application/vnd.ms-fontobject image/svg+xml;
- # Vue Router 历史模式支持
- location / {
- try_files $uri $uri/ /index.html;
- }
- # API 代理配置
- location /api {
- # 后端服务地址(请修改为实际后端地址)
- proxy_pass http://127.0.0.1:8000;
-
- # 代理头设置
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
-
- # 超时设置
- proxy_connect_timeout 300;
- proxy_send_timeout 300;
- proxy_read_timeout 300;
-
- # 缓冲设置
- proxy_buffering on;
- proxy_buffer_size 4k;
- proxy_buffers 8 4k;
- proxy_busy_buffers_size 8k;
-
- # 不代理错误到客户端
- proxy_intercept_errors on;
- }
- # 静态资源缓存配置
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
- expires 1y;
- add_header Cache-Control "public, immutable";
-
- # 启用 CORS(如果需要)
- add_header 'Access-Control-Allow-Origin' '*' always;
- add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
- add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
- }
- # 禁止访问隐藏文件
- location ~ /\. {
- deny all;
- access_log off;
- log_not_found off;
- }
- # 禁止访问特定文件
- location ~* \.(git|svn|htaccess|htpasswd) {
- deny all;
- }
- # 安全头设置
- add_header X-Frame-Options "SAMEORIGIN" always;
- add_header X-Content-Type-Options "nosniff" always;
- add_header X-XSS-Protection "1; mode=block" always;
- # SSL 配置(启用 HTTPS 时取消注释)
- # listen 443 ssl http2;
- # ssl_certificate /path/to/cert.pem;
- # ssl_certificate_key /path/to/key.pem;
- # ssl_protocols TLSv1.2 TLSv1.3;
- # ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
- # ssl_prefer_server_ciphers on;
- # ssl_session_cache shared:SSL:10m;
- # ssl_session_timeout 10m;
- }
- # HTTP 重定向到 HTTPS(启用 HTTPS 时取消注释)
- # server {
- # listen 80;
- # server_name yourdomain.com www.yourdomain.com;
- # return 301 https://$server_name$request_uri;
- # }
|