45 lines
1.3 KiB
Nginx Configuration File
45 lines
1.3 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost _; # 添加通配符,接受任何域名
|
|
|
|
# 添加 gzip 压缩
|
|
gzip on;
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|
|
|
# 设置客户端最大body大小
|
|
client_max_body_size 20M;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# 支持 history 路由模式
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
# 添加跨域支持
|
|
add_header 'Access-Control-Allow-Origin' '*';
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
|
}
|
|
|
|
# 缓存静态资源
|
|
location /assets {
|
|
expires 1y;
|
|
add_header Cache-Control "public, no-transform";
|
|
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;
|
|
}
|
|
} |