nginx的配置代码是这样的
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /home/ubuntu/card/public;
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:3000;
}
}
node程序本身没有问题
我的理解是try_files 如果不成功,应该让express服务器尝试响应
假设你的目录
/home/ubuntu/card/public
下有个叫uploads的文件夹,nginx配置如下那么访问http://localhost/会跳到nodejs,http://localhost/uploads/会访问
/home/ubuntu/card/public/uploads
下的静态文件。