使用 mod_jk 通过 apache 服务器重定向 tomcat 上的子域
我有 Tomcat (6.0.20) 和 Apache Server 设置 (2.2),并尝试将所有子域重定向到我的域上的特定上下文。
例如,s.example.com 重定向到 www.example.com
Apache 正在通过 mod_jk
转发请求(我尝试了 mod_proxy
,但是 css 和 js 没有加载不是绝对网址)。
我当前的设置:
httpd.conf:
Include C:/apache-tomcat-6.0.20/conf/auto/mod_jk.conf
RewriteEngine On
<VirtualHost *:80>
ServerName www.example.co.za
ServerAlias www.example.co.za example.co.za *.example.co.za
RewriteEngine on
RewriteLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/rewrite.log"
RewriteLogLevel 3
RewriteCond %{HTTP_HOST} example\.co\.za.*$ [NC]
RewriteRule ^(.*)$ http://www.example.co.za [L]
JkMount /* worker1
</VirtualHost>
JkMount /* worker1
server.xml:
<Host name="www.example.co.za" appBase="hosts/example"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="C:/apache-tomcat-6.0.20/logs" prefix="localhost_access_log."
suffix=".txt" pattern="common" resolveHosts="false"/>
<Context path="" docBase="Property"/>
<Alias>*.example.co.za</Alias>
</Host>
ww.example.com 的重定向将进入不间断的重定向循环。
从安全角度来看,这一点极其重要,因为用户可以访问 tomcat 管理器和服务器上的其他应用程序(即 hudson)。
I have a Tomcat (6.0.20) and Apache Server setup (2.2) and am trying to redirect all subdomains to a specific context, on my domain.
e.g., s.example.com redirect to www.example.com
Apache is fowarding requests via mod_jk
(I tried mod_proxy
, but the css and js didn't load as its not absolute urls).
My current setup:
httpd.conf:
Include C:/apache-tomcat-6.0.20/conf/auto/mod_jk.conf
RewriteEngine On
<VirtualHost *:80>
ServerName www.example.co.za
ServerAlias www.example.co.za example.co.za *.example.co.za
RewriteEngine on
RewriteLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/rewrite.log"
RewriteLogLevel 3
RewriteCond %{HTTP_HOST} example\.co\.za.*$ [NC]
RewriteRule ^(.*)$ http://www.example.co.za [L]
JkMount /* worker1
</VirtualHost>
JkMount /* worker1
server.xml:
<Host name="www.example.co.za" appBase="hosts/example"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="C:/apache-tomcat-6.0.20/logs" prefix="localhost_access_log."
suffix=".txt" pattern="common" resolveHosts="false"/>
<Context path="" docBase="Property"/>
<Alias>*.example.co.za</Alias>
</Host>
The redirect for ww.example.com is going into a non-stop redirect loop.
This is extremely important from a security point of view as the user could access the tomcat manager and other apps on the server (namely hudson).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下规则:
如果您想保留请求的 URI:
另外,我建议您使用 301 重定向。 因此,通过将
[L]
替换为[L,R=301]
来添加值为 301 的R
标志。Try this rule:
And if you want to keep the requested URI:
Additionally I recommend you to use a 301 redirection. So add the
R
flag with the value 301 by replacing[L]
with[L,R=301]
.