45 lines
1.0 KiB
Nginx Configuration File
45 lines
1.0 KiB
Nginx Configuration File
server {
|
||
listen 8080;
|
||
server_name localhost;
|
||
root /usr/share/nginx/html;
|
||
index index.html;
|
||
|
||
# 启用 gzip 压缩
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_min_length 1024;
|
||
gzip_proxied any;
|
||
gzip_types
|
||
text/plain
|
||
text/css
|
||
text/xml
|
||
text/javascript
|
||
application/javascript
|
||
application/xml+rss
|
||
application/json;
|
||
|
||
# 处理静态资源
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# SPA 路由支持 - 关键配置
|
||
location / {
|
||
try_files $uri $uri/ @fallback;
|
||
}
|
||
|
||
# 回退到 index.html,这是 SPA 路由的核心
|
||
location @fallback {
|
||
rewrite ^.*$ /index.html last;
|
||
}
|
||
|
||
# 安全头部
|
||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||
add_header X-Content-Type-Options "nosniff" always;
|
||
add_header X-XSS-Protection "1; mode=block" always;
|
||
|
||
# 错误页面
|
||
error_page 404 /index.html;
|
||
} |