Nginx proxy pointing to root of node server URL bu

2019-08-26 23:11发布

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);.

标签: node.js nginx
1条回答
Animai°情兽
2楼-- · 2019-08-26 23:35
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.

查看更多
登录 后发表回答