首页 > 解决方案 > Apache 在充当反向代理时重写

问题描述

我想使用 apache 重写将进入第二个文件夹的任何内容重定向到站点的根目录或 /。但是,当我访问http://example.com/second/css/style.css时,它并没有打开http://example.com/css/style.css

我尝试了以下方法: Apache Reverse Proxy ReWrite 但是当我将 ProxyHTMLEnable On 放在我的 conf 文件中时,apache 无法启动。

这就是我现在正在尝试的。Apache 确实启动了,但我没有得到想要的重定向效果:

    <VirtualHost *:80>
        ServerName example.com
        ServerAdmin admin@example.com

        SetEnvIf Request_URI ".(jpg|jpeg|png|swf|css|gif|dat|ico|js)$" dontlog

        #SetEnvIf Request_URI "/cron/" dontlog
        LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" varnishcombined

        RewriteEngine On
        RewriteRule ^second/(.*)$ /$1 [R=301,NC,L]
       # ProxyRequests Off
       # <Proxy *>
       #   Order deny,allow
       #   Allow from all
       # </Proxy>
        ProxyPass / http://127.0.0.1:8080/second/
        ProxyPassReverse / http://127.0.0.1:8080/second/
        <Location />
          Order allow,deny
          Allow from all
        </Location>
   </VirtualHost>

标签: apachetomcatmod-rewriteurl-rewritingreverse-proxy

解决方案


Please try with below setting in conf file because I am able to succeed with 0.0.0.0.

ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8080/second/
ProxyPassReverse / http://0.0.0.0:8080/second/

推荐阅读