What's the best way to redirect a Tomcat 404 URL with Apache as front-end?

纵然是瞬间 提交于 2021-02-11 12:20:20

问题


I have Apache 2.4 forwarding *:80 traffic to my sole Tomcat 7.0 webapp (Guacamole) like so:

ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://localhost:8080/guacamole/
ProxyPassReverse / http:/localhost:8080/guacamole/
ProxyPassReverseCookiePath / http://localhost:8080/guacamole

This works, except when I log out of the webapp, I get the following 404 as reported by Tomcat:

HTTP Status 404 - /guacamole/guacamole/index.xhtml

From what I've read I've got several options, including using ProxyPass/redirect, rewrite, VirtualHost, and symlinks. Some of these options are possible under both Apache and Tomcat configs. I'm confused. What's the best method to ensure /guacamole/guacamole/index.xhtml (or *) requests get to to /guacamole/index.xhtml?

(I know no Java if the actual root cause is in the Guacamole webapp code.)


回答1:


To anyone who stumbles across this issue, I was able to resolve from Suresh Atta's answer to this question.

Basically all that I had to do was create a custom 404 html in /var/lib/tomcat/webapps/guacamole/logout.html which contains a polite message and invitation to log in again:

<html>
<h2 align=center>Thank you. You're now logged out.</h2>
<h2 align=center>If this was a mistake or you'd like to begin a new session, 
please <a href="http://guacamoleapp.address.com">click here.</a></h2>
</html>

And then I added this directive to web.xml:

<error-page>
  <error-code>404</error-code>
  <location>/logout.html</location>
</error-page>

I'm sure there's a little cleaner way to do this, but the requirements are low for this right now, and this smoothed the rough edge.



来源:https://stackoverflow.com/questions/39360381/whats-the-best-way-to-redirect-a-tomcat-404-url-with-apache-as-front-end

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