nginx.conf.bak 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log notice;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. use epoll;
  8. multi_accept on;
  9. }
  10. http {
  11. include /etc/nginx/mime.types;
  12. default_type application/octet-stream;
  13. # 日志格式
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main;
  18. # 基本配置
  19. sendfile on;
  20. tcp_nopush on;
  21. tcp_nodelay on;
  22. keepalive_timeout 65;
  23. types_hash_max_size 2048;
  24. client_max_body_size 10M;
  25. # Gzip 压缩
  26. gzip on;
  27. gzip_vary on;
  28. gzip_min_length 1024;
  29. gzip_proxied any;
  30. gzip_comp_level 6;
  31. gzip_types
  32. text/plain
  33. text/css
  34. text/xml
  35. text/javascript
  36. application/json
  37. application/javascript
  38. application/xml+rss
  39. application/atom+xml
  40. image/svg+xml;
  41. # 安全头
  42. add_header X-Frame-Options "SAMEORIGIN" always;
  43. add_header X-Content-Type-Options "nosniff" always;
  44. add_header X-XSS-Protection "1; mode=block" always;
  45. add_header Referrer-Policy "no-referrer-when-downgrade" always;
  46. server {
  47. listen 80;
  48. server_name _;
  49. root /usr/share/nginx/html;
  50. index index.html index.htm;
  51. # 如果请求根目录,重定向到 index.html
  52. location = / {
  53. try_files $uri $uri/ /index.html;
  54. }
  55. # 静态资源缓存
  56. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  57. expires 1y;
  58. add_header Cache-Control "public, immutable";
  59. access_log off;
  60. }
  61. # HTML 文件不缓存
  62. location ~* \.html$ {
  63. expires -1;
  64. add_header Cache-Control "no-cache, no-store, must-revalidate";
  65. add_header Pragma "no-cache";
  66. }
  67. # API 代理(可选,如果需要代理到后端)
  68. location /api/ {
  69. proxy_pass http://LQAdminServer:8000/api/;
  70. proxy_set_header Host $host;
  71. proxy_set_header X-Real-IP $remote_addr;
  72. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  73. proxy_set_header X-Forwarded-Proto $scheme;
  74. proxy_connect_timeout 30s;
  75. proxy_send_timeout 30s;
  76. proxy_read_timeout 30s;
  77. }
  78. # OAuth 代理
  79. location /oauth/ {
  80. proxy_pass http://LQAdminServer:8000/oauth/;
  81. proxy_set_header Host $host;
  82. proxy_set_header X-Real-IP $remote_addr;
  83. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  84. proxy_set_header X-Forwarded-Proto $scheme;
  85. }
  86. # SPA 路由支持
  87. location / {
  88. try_files $uri $uri/ /index.html;
  89. }
  90. # 健康检查
  91. location /health {
  92. access_log off;
  93. return 200 "healthy\n";
  94. add_header Content-Type text/plain;
  95. }
  96. # 安全配置
  97. location ~ /\. {
  98. deny all;
  99. access_log off;
  100. log_not_found off;
  101. }
  102. }
  103. }