基于子路径反向代理两台服务器

时间:2016-01-08 01:42:27

标签: apache reverse-proxy

apache问题。必须是简单的事情,但我失败了。

我正在尝试将apache配置为其后面的两个服务器的反向代理。棘手的部分是注册代理规则的唯一区别是子路径。

我的想法是:

mydomain.com -> localhost:8083
mydomain.com/api -> localhost:8080/api

目前我的配置是:

<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyRequests Off
        ServerName mydomain.com
        ServerAlias www.mydomain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyPass / http://localhost:8083/
        ProxyPassReverse / http://localhost:8083/

        ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters
        ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters

</VirtualHost>

但是/ api无法正常工作,它会继续向8083发送请求。有什么想法可以解释?

感谢关注

1 个答案:

答案 0 :(得分:4)

尝试在'/'之前执行'/ api'ProxyPass + ProxyPassReverse。我强烈怀疑'/'是一个笼罩而且你永远不会进入'/ api'的情况。这可以解释为什么你总是去8083,这是'/'的情况。

<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyRequests Off
        ServerName mydomain.com
        ServerAlias www.mydomain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters
        ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters

        # do this last...
        ProxyPass / http://localhost:8083/
        ProxyPassReverse / http://localhost:8083/


</VirtualHost>