Nginx proxy pointing to root of node server URL bu

2019-08-26 23:39发布

问题:

I have an Nginx server running and redirecting proxy to a node server:

  server {
        listen      80 default_server;

        root /usr/share/nginx/html;

        index index.html index.htm;

        location / {
            try_files $uri /index.html;
        }

    location /api {
        proxy_pass http://node_server:9000;
    }

Site URL is example.com, but when you go to example.com/api, it should go to the root of the node server.

When I do app.use('/', indexRouter);, though, it doesn't work.

I have to do app.use('/api', indexRouter);.

回答1:

server {
    listen      80 default_server;

    root /usr/share/nginx/html;

    index index.html index.htm;

    location / {
        try_files $uri /index.html;
    }

    location /api {
        proxy_pass http://node_server:9000/;
        #                                 ^
    }
}

Had to add a forward slash.



标签: node.js nginx