【问题标题】:Apache rewrite while acting as a reverse proxyApache 在充当反向代理时重写
【发布时间】:2019-07-01 02:06:30
【问题描述】:
  • 我有 example.com:8080/second 在 Apache Tomcat 上运行。
  • 我将 Apache2 作为反向代理,为 example.com 上的页面提供服务 80 端口
  • 很多代码都指向“第二个”目录,但是 因为 Apache 充当反向代理 example.com:8080/second 看不到“第二个”目录 浏览器。

我想使用 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>

【问题讨论】:

    标签: apache tomcat mod-rewrite url-rewriting reverse-proxy


    【解决方案1】:

    请在 conf 文件中尝试以下设置,因为我可以使用 0.0.0.0 成功。

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

    【讨论】:

    • 我将配置中的 ProxyPass 和 ProxyPassReverse 行替换为 3 行并重新启动 apache。 example.com 可以正常运行,但如果我尝试 example.com/second/css/style.css,我会得到 404。我需要该 url 转发到 example.com/css/style.css
    猜你喜欢
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2012-11-16
    • 1970-01-01
    • 2014-03-24
    • 2014-02-01
    • 1970-01-01
    相关资源
    最近更新 更多