- 我在 Apache Tomcat 上运行 example.com:8080/second。
- 我将 Apache2 作为反向代理服务于 example.com 上的页面 端口 80
- 很多代码都指向“第二个”目录,但是 因为 Apache 充当反向代理 example.com:8080/second 看不到“second”目录 浏览器。
我想使用 apache 重写将任何进入第二个文件夹的内容重定向到站点的根目录或/。然而,当我去 http://example.com/second/css/style.css它不拉起http://example.com/css/style.css
我尝试了以下方法: Apache Reverse Proxy ReWrite 但是当我将 ProxyHTMLEnable 放在我的 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>
最佳答案
请尝试在 conf 文件中使用以下设置,因为我能够成功使用 0.0.0.0。
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8080/second/
ProxyPassReverse / http://0.0.0.0:8080/second/
关于Apache 在充当反向代理时进行重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54565173/