| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- server {
- listen 8080;
- server_name localhost;
- root /usr/share/nginx/html;
- index index.html index.htm;
- # 安全头
- add_header X-Frame-Options "SAMEORIGIN" always;
- add_header X-XSS-Protection "1; mode=block" always;
- add_header X-Content-Type-Options "nosniff" always;
- add_header Referrer-Policy "no-referrer-when-downgrade" always;
- # 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/javascript
- application/json
- application/xml+rss
- application/atom+xml
- image/svg+xml;
- # 主路由 - SPA 支持
- location / {
- try_files $uri $uri/ /index.html;
-
- # 安全头
- add_header Cache-Control "no-cache, no-store, must-revalidate";
- add_header Pragma "no-cache";
- add_header Expires "0";
- }
- # 静态资源缓存
- location /static/ {
- expires 1y;
- add_header Cache-Control "public, immutable";
- access_log off;
- }
- # 字体文件
- location ~* \.(woff|woff2|ttf|eot)$ {
- expires 1y;
- add_header Cache-Control "public, immutable";
- access_log off;
- }
- # 图片文件
- location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
- expires 1y;
- add_header Cache-Control "public, immutable";
- access_log off;
- }
- # CSS 和 JS 文件
- location ~* \.(css|js)$ {
- expires 1y;
- add_header Cache-Control "public, immutable";
- access_log off;
- }
- # manifest 和 service worker
- location ~* \.(manifest\.json|sw\.js)$ {
- expires 0;
- add_header Cache-Control "no-cache, no-store, must-revalidate";
- access_log off;
- }
- # 禁止访问隐藏文件
- location ~ /\. {
- deny all;
- access_log off;
- log_not_found off;
- }
- # 错误页面
- error_page 404 /index.html;
- error_page 500 502 503 504 /50x.html;
-
- location = /50x.html {
- root /usr/share/nginx/html;
- }
- }
|