search

Home  >  Q&A  >  body text

express - nginx runs the node program, the routing jump is 404, and static files can be loaded normally

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中文网2744 days ago1087

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦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;  

    }

    reply
    0
  • 漂亮男人

    漂亮男人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.

    reply
    0
  • Cancelreply