update
This commit is contained in:
parent
8f91bbdddd
commit
a06b8f2ff7
71
nginx.conf
71
nginx.conf
@ -1,43 +1,64 @@
|
|||||||
server {
|
# 移除 user 指令,因为我们以非 root 用户运行
|
||||||
|
worker_processes auto;
|
||||||
|
pid /var/run/nginx.pid;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
|
||||||
|
access_log /var/log/nginx/access.log main;
|
||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
gzip on;
|
||||||
|
|
||||||
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
|
||||||
# 开启gzip
|
# 添加 gzip 压缩
|
||||||
gzip on;
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||||
gzip_min_length 1k;
|
|
||||||
gzip_comp_level 9;
|
|
||||||
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
|
||||||
gzip_vary on;
|
|
||||||
|
|
||||||
# 禁用缓存,解决前端缓存问题
|
# 设置客户端最大body大小
|
||||||
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
|
client_max_body_size 20M;
|
||||||
add_header Pragma "no-cache";
|
|
||||||
add_header Expires "0";
|
|
||||||
|
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# 支持 history 路由模式
|
||||||
location / {
|
location / {
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html index.htm;
|
|
||||||
# 处理单页应用路由
|
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
}
|
}
|
||||||
|
|
||||||
# 缓存静态资源,但排除 JavaScript 文件
|
# 缓存静态资源
|
||||||
location ~* \.(jpg|jpeg|png|gif|ico|css)$ {
|
location /assets {
|
||||||
root /usr/share/nginx/html;
|
expires 1y;
|
||||||
expires 1d;
|
add_header Cache-Control "public, no-transform";
|
||||||
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
# JavaScript 文件不缓存
|
# 禁止访问 . 文件
|
||||||
location ~* \.js$ {
|
location ~ /\. {
|
||||||
root /usr/share/nginx/html;
|
deny all;
|
||||||
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
|
access_log off;
|
||||||
add_header Pragma "no-cache";
|
log_not_found off;
|
||||||
add_header Expires "0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 错误页面
|
# 错误页面配置
|
||||||
|
error_page 404 /index.html;
|
||||||
error_page 500 502 503 504 /50x.html;
|
error_page 500 502 503 504 /50x.html;
|
||||||
location = /50x.html {
|
location = /50x.html {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user