Nginx代理指向节点服务器URL的根,但是节点响应完整的URL? [英] Nginx proxy pointing to root of node server URL but node responds to full URL?

查看:284
本文介绍了Nginx代理指向节点服务器URL的根,但是节点响应完整的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的Nginx服务器并将代理重定向到节点服务器:

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;
    }

站点URL是example.com,但是当您访问example.com/api时,它应该转到节点服务器的根目录.

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

但是,当我执行app.use('/', indexRouter);时,它不起作用.

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

我必须做app.use('/api', indexRouter);.

推荐答案

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/;
        #                                 ^
    }
}

必须添加正斜杠.

这篇关于Nginx代理指向节点服务器URL的根,但是节点响应完整的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆