【问题标题】:How to implement a reverse proxy for one subdomain如何为一个子域实现反向代理
【发布时间】:2015-07-25 06:42:26
【问题描述】:

我在防火墙后面有一组服务器。它只支持端口转发。到目前为止,我所有的子域(www.、server.、beta.、cloud.)都在一台服务器(OS X Server)上。

我也有一个开发者。位于单独的 Freebsd 服务器上的子域。形成我的内部网络,我可以使用我的 DNS 将流量发送到开发人员的正确服务器。子域。但是当我从外部访问时,我无法通过端口 80 访问开发服务器,因为该端口被转发到主服务器。

我不想使用非标准端口,而是想从我的主服务器反向代理回到开发服务器,但看起来这适用于 URL,而不适用于子域。有没有办法可以通过我的主服务器将 dev.example.com 的所有请求路由到内部开发服务器。

谢谢..

【问题讨论】:

    标签: reverse-proxy


    【解决方案1】:

    是的,这是所有常见 rproxy 的标准用例,您会在它们各自的文档中找到几乎可以使用的示例。使用 nginx,基本设置如下所示(将这个文件放在 enabled-sites 子目录中):

    server {
        # prod marked as default so lost traffic ends up on production
        listen 192.168.0.1:80 default;
        server_name production.your.domain;
    
        access_log /var/log/nginx/production-access.log;
    
        location / {
            proxy_pass http://your.production.server:80;
        }
    }
    
    server {
        listen 192.168.0.1:80;
        server_name dev.your.domain;
    
        access_log /var/log/nginx/development-access.log;
    
        location / {
            proxy_pass http://your.development.server:80;
        }
    }
    

    使用 Pound 你可以使用类似的东西

    Service
      HeadRequire "Host: .*production.your.domain.*"
      BackEnd
        Address your.production.server
        Port    80
      End
    End
    
    Service
      HeadRequire "Host: .*dev.your.domain.*"
      BackEnd
        Address your.development.server
        Port    80
      End
    End
    
    # and a safety net for lost traffic
    Service
      URL "/"
      Redirect "http://production.you.domain"
    end;
    

    Apache 的 mod_proxy 也是可能的,但由于缺乏该组合的实践经验,我不得不从 Atlassian documentation webpage 借用一个示例:

    # Put this after the other LoadModule directives
    LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
    LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
    
    # Put this with your other VirtualHosts, or at the bottom of the file
    NameVirtualHost *
    <VirtualHost *>
        ServerName confluence.example.com
    
        ProxyRequests Off
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
    
        ProxyPass / http://confluence-app-server.internal.example.com:8090/
        ProxyPassReverse / http://confluence-app-server.internal.example.com:8090/
        <Location />
            Order allow,deny
            Allow from all
        </Location>
    </VirtualHost>
    <VirtualHost *>
        ServerName jira.example.com
    
        ProxyRequests Off
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
    
        ProxyPass / http://jira-app-server.internal.example.com:8080/
        ProxyPassReverse / http://jira-app-server.internal.example.com:8080/
        <Location />
            Order allow,deny
            Allow from all
        </Location>
    </VirtualHost>
    

    【讨论】:

    • @MB 查看编辑 - 请注意,前两个来自我正在运行的配置(所以我非常有信心他们会做我声称他们做的事情,Apache 同样是从一个外部文档站点,虽然看起来还不错,但我不能保证它的正确性。
    猜你喜欢
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2021-12-18
    • 2017-10-04
    • 2017-07-19
    • 2016-09-13
    • 2018-02-14
    • 1970-01-01
    相关资源
    最近更新 更多