【发布时间】: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