Nginx 反向代理 - 由尾部斜杠分隔的内部服务器 [英] Nginx reverse proxy - Internal servers separated by trailing slash

查看:90
本文介绍了Nginx 反向代理 - 由尾部斜杠分隔的内部服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Nginx 的新手,一直在为我的问题寻找正确的答案,但找不到;不是因为它不存在,而是我的新手状况限制了我对我的问题采用通用解决方案.

I'm a newbie at Nginx, and have been searching a lot for the right answer to my question, but couldn't find it; not because it is not there, but my newbie condition limits me to adapt a generic solution to my issue.

情况是这样的:我的私人局域网中有一个 Mantis Bug Tracker (http://10.111.111.12).另一方面,我的 LAN 上也有一个 OwnCloud 网站(IP 10.111.111.5),网址为 http://10.111.111.5/owncloud/.

The situation is this: I have a Mantis Bug Tracker in my private LAN (http://10.111.111.12). On the other hand, i have an OwnCloud website also on my LAN (IP 10.111.111.5), with URL http://10.111.111.5/owncloud/.

我想要做的是部署一个 Nginx 反向代理来处理来自 publicdomain.com 的所有 Internet 请求,并为每个内部网络服务器使用尾部斜杠.期望的结果是:

What i want to do is to deploy a Nginx Reverse Proxy that handles all requests from Internet at publicdomain.com, and use trailing slash for each internal webserver. The desired result would be:

http://www.publicdomain.com/bugtracker ->重定向到 http://10.111.111.12/index.phphttp://www.publicdomain.com/cloud ->重定向到 http://10.111.111.5/owncloud/(请注意,cloud"比";自己的云")

http://www.publicdomain.com/bugtracker -> redirects to http://10.111.111.12/index.php http://www.publicdomain.com/cloud -> redirects to http://10.111.111.5/owncloud/ (note that "cloud" is preferred over "owncloud")

以后需要继续使用斜杠来部署其他Web服务器.

On the future, it is necessary to continue using trailing slash for other web servers to be deployed.

问题是:这种情况可能吗?如果是这样,配置 nginx 就足够了,还是我必须重新配置内部 Web 服务器?

Questions are: is this scenario possible? if so, is it enough with configuring nginx or I have to reconfigure internal web servers as well?

我非常感谢您的帮助,在以前的帖子中向我指出可能的解决方案或为我指明正确的方向.

I really appreciate your help, by indicating me a possible solution or pointing me to the right direction on previous posts.

非常感谢.

推荐答案

是的,可以实现这样的配置,它通常用于 NGINX 作为反向代理.您可以使用此配置作为构建您自己的配置的灵感:

Yes it is possible to achieve such configuration and it's commonly used when NGINX is acting as a reverse proxy. You can use this configuration as an inspiration for building your own:

upstream bugtracker {
  server 10.111.111.12;
}

upstream cloudupstream {
  server 10.111.111.5;
}

server {
  listen 80;
  location /bugtracker/{
    proxy_pass http://bugtracker;
  }
  location /cloud/{
    proxy_pass http://cloudupstream/owncloud;
  }
}

这里发生的事情是 nginx 将侦听端口 80,一旦收到路径/bugtracker 的请求,它就会自动将请求路由到上述上游服务器.使用它,您可以根据需要添加任意数量的上游服务器和位置块.参考:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

What's happening over here is that nginx will be listening on port 80 and as soon as a request comes for path /bugtracker, it will automatically route the request to the upstream server mentioned above. Using this you can add as many upstream servers and location blocks as you want. Reference: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

这篇关于Nginx 反向代理 - 由尾部斜杠分隔的内部服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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