{"id":2346,"date":"2014-01-11T09:11:59","date_gmt":"2014-01-11T13:11:59","guid":{"rendered":"http:\/\/linuxhostingsupport.net\/blog\/?p=2346"},"modified":"2014-01-11T09:14:04","modified_gmt":"2014-01-11T13:14:04","slug":"how-to-make-tomcat-work-on-port-80-instead-of-8080","status":"publish","type":"post","link":"https:\/\/linuxhostingsupport.net\/blog\/how-to-make-tomcat-work-on-port-80-instead-of-8080","title":{"rendered":"How to make Tomcat work on port 80 instead of 8080?"},"content":{"rendered":"<p><strong>Sometimes people host applications that are fully Java based and don&#8217;t require a Webserver to access their application.<\/strong> However, in such a case, the application has to be accessed with port 8080 i.e. http:\/\/domainname:8080 which is not feasible.<\/p>\n<p>There are 2 ways for the Java application to work on port 80, so people don&#8217;t have to mention port 8080 in their URL\u00a0We will take a look at each of the above 2 options below:<\/p>\n<p><strong>1.<\/strong> The easiest way is to <strong>change the Tomcat port from port 8080 to 80 in the conf\/server.xml file. <\/strong>This file is inside the Tomcat folder.<strong>\u00a0<\/strong><\/p>\n<p>To locate the file, update the mlocate database first (this command will take sometime to complete):<\/p>\n<blockquote>\n<pre># updatedb<\/pre>\n<\/blockquote>\n<p>now, search the server.xml file using the locate command:<\/p>\n<blockquote>\n<pre># locate server.xml<\/pre>\n<\/blockquote>\n<p>Open the file in the edit mode<\/p>\n<blockquote>\n<pre># nano server.xml<\/pre>\n<\/blockquote>\n<p>and search for the below section<\/p>\n<blockquote>\n<pre>&lt;Connector port=\"8080\" Protocol=\"HTTP\"\r\nmaxHttpHeaderSize=\"8192\"\r\nconnectionTimeout=\"20000\"\r\n\/&gt;<\/pre>\n<\/blockquote>\n<p>Replace port 8080 with 80 and restart the Tomcat service.<\/p>\n<p><strong>2.<\/strong>\u00a0<strong>The second method is to use iptables rules to redirect traffic received on port 80 to port 8080.<\/strong><\/p>\n<p>To add the iptables redirect rules, SSH to your server as root and execute the below commands:<\/p>\n<blockquote>\n<pre># iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT\r\n# iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT\r\n# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j \\\r\nREDIRECT --to-port 8080<\/pre>\n<\/blockquote>\n<p>To make the rules permanent<\/p>\n<blockquote>\n<pre># service iptables save<\/pre>\n<\/blockquote>\n<p>Applying any of the above 2 methods will make the Java application work without the use of port 8080 in the URL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes people host applications that are fully Java based and don&#8217;t require a Webserver to access their application. However, in such a case, the application has to be accessed with port 8080 i.e. http:\/\/domainname:8080 which is not feasible.<br \/>\nThere are 2 ways for the Java application to work on port 80, so people don&#8217;t have to mention port 8080 in their URL\u00a0We will take a look at each of the above 2 options below:<br \/>\n1. The easiest way is to change the Tomcat port from port 8080 to 80 in [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[1486,1482,1484,1483,1485],"_links":{"self":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/2346"}],"collection":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/comments?post=2346"}],"version-history":[{"count":11,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/2346\/revisions"}],"predecessor-version":[{"id":2357,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/2346\/revisions\/2357"}],"wp:attachment":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/media?parent=2346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/categories?post=2346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/tags?post=2346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}