0

I am using centOs VPS server with root access. I am using Apache Tomcat to run my java application. The problem that i am facing is that the Tomcat runs on port no 8080 and the default port no of Domain is 80. so whenever i hit my domain name it move to port no 80 where nothing is present. My application is working perfectly fine on domain.com:8080/.

I want when even i hit my domain domain.com . it automatically open my Java application. It does not show me the empty space.

I don't want to change my default port no of tomcat to 80. Is there any way to change the port no. of the website. i am having the root access and using WHMCpanel.

2 Answers2

2

HTTP protocol works on port 80 if you don't specify it. So somehow you need to find a way that when you reach the server at port 80, it redirects it to Tomcat.

I don't want to change my default port no of tomcat to 80. Is there any way to change the port no. of the website. i am having the root access and using WHMCpanel.

The answer is "depends". There are couple workarounds and a good solution to go:

  • You can create a simple webpage or configure the Apache or Nginx to redirect you to http://domain.com:8080 with a 302 redirection. I don't really recommend to go on that direction, but if you don't want to modify the ports.

  • Also, there's a trick with iptables where you can redirect the port 80 to 8080, but it that case you'd need to switch off the webserver running at port 80 as the port is already bound.

The good solution: Switch off Nginx or Apache and configure on server.xml the port to 80. Refer to this post for more details.

Community
  • 1
  • 1
Alex Roig
  • 1,534
  • 12
  • 18
0

Nothing seems to be present on port 80 so you could switch off what is running on port 80. Then do not run tomcat on port 80 because tomcat will need root and this is not a good solution.

The good solution is to redirect port 80 on port 8080 using iptable:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

then to make it persistent:

apt-get install iptables-persistent
iptables-save > /etc/iptables/rules.v4