34 lines
855 B
Nginx Configuration File
34 lines
855 B
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost; # 通配符,匹配所有域名(适用于反向代理场景)
|
|
|
|
# 开启 gzip 压缩
|
|
gzip on;
|
|
gzip_min_length 1k;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
|
gzip_vary on;
|
|
gzip_disable "MSIE [1-6]\.";
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# 解决 SPA 路由刷新 404 问题
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# 静态资源缓存配置
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public, no-transform";
|
|
}
|
|
|
|
# 错误页面
|
|
error_page 500 502 503 504 /50x.html;
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
}
|
|
}
|
|
|