How to display Maintenance page for my application deployed in Tomcat?

爷,独闯天下 提交于 2020-01-22 15:59:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!