apache - Apache 在充当反向代理时重写
问题描述
- 我在 Apache Tomcat 上运行了 example.com:8080/second。
- 我有 Apache2 作为反向代理,在端口 80 上为 example.com 提供页面
- 很多代码都指向“第二”目录,但是因为 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>
解决方案
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/
推荐阅读
- laravel - Laravel Eloquent with() 位置搜索
- c# - 为什么我不能在 Sql 中使用循环?有什么更好的方法来解决这种问题?
- javascript - 重复值的数组
- c++ - 使用 PkgConfig 和 MSVC 找到 SDL(不编译)
- javascript - 检测脚本是否在 Runkit 中运行
- python - PYTHON 和批处理脚本:如果文件存在则运行文件,如果不存在则创建
- regex - 正则表达式检查是否包含超过 2 个重复字符
- python - 使用python根据值对列表中的键值对进行排序
- ios - 支持 iOS 应用的深色模式有多重要
- spring-boot - 哪个连接池实现具有我想要的行为?