Changing Tomcat server name in response header, is that possible?

感情迁移 提交于 2019-12-22 08:04:17

问题


When a http request from a browser is made, typically the server container will send along in the header what server it was.

For tomcat it sends

   Server:Apache-Coyote/1.1

I know I can overwrite this header, for each request, but there is also the case for websockets and potentially other connections.

So, is there a way to change this at the tomcat configuration level?


回答1:


I just found this after posting the question:

Add this to server.xml in tomcat config folder.

<Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443"
                   server="MYSERVER"
                />

seems to work.

Restart server.




回答2:


Programmatically, given a org.apache.catalina.connector.Connector, it's: connector.setAttribute("server", "Something")

Caution: Coyote ignores the server name if it's an empty string.



来源:https://stackoverflow.com/questions/36664816/changing-tomcat-server-name-in-response-header-is-that-possible

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