Tomcat 8.0 重写 Valve [英] Tomcat 8.0 Rewrite Valve
问题描述
我正在尝试在 Tomcat 8.0 中使用 RewriteValve http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html
I am trying to use the RewriteValve in Tomcat 8.0 http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html
在 $CATALINA_HOME/conf/server.xml 中,我添加了
In $CATALINA_HOME/conf/server.xml, I added
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
就在 Host 标签下方
right below the Host tag
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
在 $CATALINA_HOME/conf
目录中创建了一个 rewrite.config
,内容如下
Created a rewrite.config
in the $CATALINA_HOME/conf
directory with the following
RewriteRule ^/abc /myapp
其中 http:/host:port/myapp
是一个正在运行的网络应用程序.
where http:/host:port/myapp
is a working webapp.
所以现在当我去 http://host:port/abc
我希望被重定向到 http://host:port/myapp
但我得到一个 404 请求的资源不可用
代替.
So now when I go to http://host:port/abc
I expect to be redirected to http://host:port/myapp
but I get a 404 the requested resource is not available
instead.
看起来它甚至没有读取我的 rewrite.config 文件.日志目录中的访问日志只报告了"GET/abc HTTP/1.1" 404 1000
,没有进一步的细节.
It doesn't look like it is even reading my rewrite.config file. The access log in the logs directory just reports the "GET /abc HTTP/1.1" 404 1000
with no further details.
我错过了什么?谢谢
推荐答案
在 Tomcat 文档中 http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html 已写
In Tomcat documentation http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html is written
重写阀可以配置为添加到主机中的阀.有关如何配置它的信息,请参阅虚拟服务器文档.它将使用包含重写指令的 rewrite.config 文件,它必须放在主机配置文件夹中.
The rewrite valve can be configured as a valve added in a Host. See virtual-server documentation for informations how to configure it. It will use a rewrite.config file containing the rewrite directives, it must be placed in the Host configuration folder.
所以尝试将 rewrite.config
移动到 $CATALINA_HOME/conf/Catalina/localhost
小提示:你可以在 rewrite.config
中拼错一些东西(例如 xxRewriteRule
),然后如果 tomcat 读取这个文件它会失败.我认为在你的情况下,即使你拼错了一些东西,tomcat 也会启动(因为它没有被读取).
so try to move rewrite.config
into $CATALINA_HOME/conf/Catalina/localhost
Small hint: you can misspell something in rewrite.config
( e.g. xxRewriteRule
) and then if tomcat reads this file it fails. I think in your case tomcat starts even if you misspell something (because it is not read).
这篇关于Tomcat 8.0 重写 Valve的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!