-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathnginx.conf.example
More file actions
72 lines (56 loc) · 1.94 KB
/
nginx.conf.example
File metadata and controls
72 lines (56 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Nginx配置示例,用于生产环境反向代理
# 将此文件放置在 /etc/nginx/sites-available/ 并创建符号链接到 sites-enabled/
upstream nextjs_app {
server localhost:3000;
}
upstream websocket_app {
server localhost:3001;
}
server {
listen 80;
server_name your-domain.com;
# 如果使用HTTPS,取消下面的注释并配置SSL证书
# listen 443 ssl;
# ssl_certificate /path/to/ssl/cert.pem;
# ssl_certificate_key /path/to/ssl/key.pem;
# 增加请求体大小限制
client_max_body_size 100M;
# Next.js应用的主要路由
location / {
proxy_pass http://nextjs_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# WebSocket专用路由
location /ws-api {
proxy_pass http://websocket_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket特定的超时设置
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
# 静态资源缓存
location /_next/static {
proxy_pass http://nextjs_app;
proxy_cache_valid 60m;
add_header Cache-Control "public, immutable";
}
location /public {
proxy_pass http://nextjs_app;
proxy_cache_valid 60m;
add_header Cache-Control "public, max-age=3600";
}
}