express - nginx runs the node program, the routing jump is 404, and static files can be loaded normally
PHP中文网
PHP中文网 2017-05-24 11:32:53
0
2
1109

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

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
伊谢尔伦

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;  

}

漂亮男人

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template