Skip to content

Commit bad2988

Browse files
author
zhaoshiwei1
committed
refactor: update nginx configuration to disable caching for Next.js resources and optimize proxy settings
1 parent 1e96c94 commit bad2988

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

nginx.conf.template

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,48 @@ server {
22
listen 80;
33
server_name powder.icu www.powder.icu;
44

5-
location / {
5+
# 禁用所有缓存
6+
proxy_cache off;
7+
proxy_buffering off;
8+
9+
# Next.js 静态资源 - 必须放在 location / 之前
10+
location /_next/ {
611
proxy_pass http://127.0.0.1:3000;
712
proxy_http_version 1.1;
8-
proxy_set_header Upgrade $http_upgrade;
9-
proxy_set_header Connection 'upgrade';
1013
proxy_set_header Host $host;
1114
proxy_set_header X-Real-IP $remote_addr;
1215
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1316
proxy_set_header X-Forwarded-Proto $scheme;
14-
proxy_cache_bypass $http_upgrade;
15-
proxy_read_timeout 86400;
17+
18+
# 禁用所有缓存
1619
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
1720
add_header Pragma "no-cache" always;
1821
add_header Expires "0" always;
22+
23+
# 禁用代理缓存
24+
proxy_cache_bypass 1;
25+
proxy_no_cache 1;
1926
}
2027

21-
location /_next/static/ {
28+
# Next.js 应用代理 - 放在最后作为兜底
29+
location / {
2230
proxy_pass http://127.0.0.1:3000;
23-
add_header Cache-Control "public, max-age=31536000, immutable";
31+
proxy_http_version 1.1;
32+
proxy_set_header Upgrade $http_upgrade;
33+
proxy_set_header Connection 'upgrade';
34+
proxy_set_header Host $host;
35+
proxy_set_header X-Real-IP $remote_addr;
36+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
37+
proxy_set_header X-Forwarded-Proto $scheme;
38+
39+
# 禁用所有缓存
40+
proxy_cache_bypass 1;
41+
proxy_no_cache 1;
42+
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
43+
add_header Pragma "no-cache" always;
44+
add_header Expires "0" always;
45+
46+
proxy_read_timeout 86400;
2447
}
2548

2649
access_log /www/wwwlogs/powder.icu.log;

0 commit comments

Comments
 (0)