如何将不同的URL重定向到同一域上的不同端口?

时间:2015-01-17 08:50:39

标签: redirect apache2 port openerp reverse-proxy

我在端口8069上运行odoo,我想在同一个域上的端口80上运行wordpress。我想将example.com *重定向到端口8069,除了example.com/wordpress*,我想转到80端口。

我知道这与Redirecting from port 80 to different ports based on URL类似。我想按照abhi-devireddy的建议实现反向代理解决方案。我尝试了以下反向代理。所有请求都转发到端口8069,包括http://example.com/wordpress/。当浏览器指向http://example.com/wordpress

时,Odoo会报告找不到错误404页面
<VirtualHost *:80>

        ServerName odoo
        ErrorLog /var/log/odoo/odoo-error.log
        CustomLog /var/log/odoo/odoo-access.log combined

        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>

        ProxyRequests Off
        ProxyPreserveHost On

        ProxyPass / http://example.com:8069/
        ProxyPassReverse / http://example.com:8069/

        ProxyPass http://example.com/wordpress/ http://example.com:80/wordpress
        ProxyPassReverse http://example.com/wordpress/ http://example.com:80/wordpress


        ProxyVia On
        LogLevel warn

</VirtualHost>

1 个答案:

答案 0 :(得分:1)

ProxyPass !从反向代理中排除网址http://example.com:80/wordpress。这允许除http://example.com:80/wordpress之外的所有内容都映射到端口8069,同时让http://example.com:80/wordpress进入端口80:

<VirtualHost *:80>

        ServerName odoo
        ErrorLog /var/log/odoo/odoo-error.log
        CustomLog /var/log/odoo/odoo-access.log combined

        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>

        ProxyRequests Off
        ProxyPass /wordpress !
        ProxyPass / http://example.com:8069/
        ProxyPassReverse / http://example.com:8069/

        Alias /wordpress /var/lib/wordpress/

        # ProxyVia On
        LogLevel warn

</VirtualHost>