How to make Tomcat run on 443 instead of its default port 8080?
Solution 1
Tomcat_home/conf/server.xml
search for
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
change 8080 to 443
Solution 2
You can change Tomcat's port in the server.xml file (located in the conf directory). To change the port you have to modify the "port" attribute of the "connector" element.
If you want to run the Tomcat server on linux and you cannot run it as a privileged user you may use iptables to redirect the port 443 to 8080: iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080
Solution 3
Look in conf/server.xml, there will be a <Connector>
element containing the attribute port="8080"
- you can change that to be whatever you want.
However, if someone's asked to to run it on 443, I'd guess what they actually want is https? In which case see http://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html for how to set up ssl on tomcat.
Shivayan
Updated on June 24, 2020Comments
-
Shivayan almost 4 years
We have a situation where we are required to run Tomcat and all its applications on port 443 instead of port 8080. Can anyone give a guidance on how this can be achieved? The process,its benefits and impacts.
-
christopher almost 10 yearsYou can alter the
server.xml
file to change the default port. -
Gyro Gearless almost 10 yearsThis question is not related to Java programming, you should rather ask it on a server admin forum. And BTW, the Tomcat guys wrote some documentation...
-
-
maress almost 10 years443 is a privileged port, so he will have to run as root too
-
Gyro Gearless almost 10 yearsAsking for application to run on port 443 indicates a requirement to use SSL, so perhaps this will not solve askers problem (although this answer is technically correct...)
-
Gyro Gearless almost 10 years@maress This only applies to unix-like OSes..
-
Shivayan almost 10 years@ abhishek i did change it to port 443 and restart the server.Then tried firing localhost:443 in the browser but the Tomcat home page didn't show up instead the url kept getting redirected to localhost:8080.
-
Abhishek Mishra almost 10 yearsI don't know why you required 443 as HTTP port,mine answer is just to inform how you change your HTTP port for tomcat,now when question arise for 443 then you should be familiar with that,i don't want to type much so just referring below url check it blog.simple-help.com/2011/12/ports-vs-protocols-80-and-443 if anyone has more useful link then please share it here.
-
Shivayan almost 10 yearswas successful in configuring the SSL ,here's the link to do it. tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html
-
alexk about 8 yearsThe linux solution is not really ideal as the user will see the 8080 address in their browser's address field. I would suggest using an AJP connector to Apache, or authbind.
-
Pere about 7 yearsThis is not a matter of "linux", @alexk
-
shakaran almost 6 yearsIn my experience and to warn to others: you have to be careful with this prerouting rule, because you can suffer error like: error:1408F10B:SSL routines:ssl3_get_record:wrong version number because the iptables will break the SSL hand shaking at some point (I have this problem with tomcat and let's encrypt in a EC2 server)
-
Samantha Adrichem over 5 yearsin case of jira the following command allows it to run on 443 with the above connector changes
setcap cap_net_bind_service=+ep /opt/atlassian/jira/jre/bin/java
so basically do this to the JRE that your tomcat is running on