问题
Considering I have multiple applications deployed in Tomcat. I had planned for maintenance for a particular application. So I want to block the request for that particular application and redirect to a static page, informing the users it is in a planned maintenance.
To achieve this with tomcat configuration, is it possible? Any help will be appreciated. Thanks!
回答1:
My solution, that I haven't seen else where, relies on the use of the RewriteValve, so it's dedicated to SO users. You will need a Tomcat restart to activate it.
Add the valve in your Host definition in $CATALINA_BASE/conf/server.xml
:
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
Edit or (more likely) create $CATALINA_BASE/conf/Catalina/localhost/rewrite.config
file with this content :
# for a missing webapp which would be named fewbars
RewriteCond %{REQUEST_PATH} ^/fewbars/.*
RewriteRule ^(.*)$ /maintenance/index.html [R,NC]
# for a deployed webapp named fewbars
RewriteCond %{CONTEXT_PATH} /fewbars
RewriteRule ^(.*)$ /maintenance/index.html [R,NC]
As commented, the behaviour depends on the webapp status : if the war file and the directory have been removed then you need to match on the REQUEST_PATH. On the contrary, to hide an application whose war and directories are still there it will be matched by CONTEXT_PATH.
You understand that you need a /maintenance/index.html
file in $CATALINA_HOME/webapps directory
来源:https://stackoverflow.com/questions/49536468/how-to-display-maintenance-page-for-my-application-deployed-in-tomcat