nginx反代静态资源404解决方案


写了几个 Node.js 的项目,想要用 NGINX 反向代理nodejs端,但是出现了静态文件404的问题。
记录一下解决方案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
upstream  node {
server localhost:3000; # Node.js 的地址
keepalive 64;
}
server{
listen 80;
server_name 域名 ;
location / {
proxy_pass http://node;
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 REMOTE-HOST $remote_addr;
#持久化连接相关配置
#proxy_connect_timeout 30s;
#proxy_read_timeout 86400s;
#proxy_send_timeout 30s;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
expires 12h;
}
}