nginx configuration code is like this
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;
}
}
There is no problem with the node program itself
伊谢尔伦2017-05-24 11:34:53
My understanding is that if try_files is unsuccessful, the express server should try to respond
location / {
root /home/ubuntu/card/public; try_files $uri $uri/ @proxy; }
location @proxy {
proxy_pass http://127.0.0.1:3000;
}
漂亮男人2017-05-24 11:34:53
Suppose there is a folder called uploads under your directory /home/ubuntu/card/public
, and the nginx configuration is as follows
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:3000;
}
location /uploads {
root /home/ubuntu/card/public/;
index index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ =404;
}
}
Then accessing http://localhost/ will jump to nodejs, and http://localhost/uploads/ will access the static files under /home/ubuntu/card/public/uploads
.