How to Change tomcat8 port 8080 to 80

2.1k Views Asked by At

I am using tomcat8 and i have changed http port in cofg/server.xml as

In http connector i have changed port 8080 to 80

< Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

I have restarted tomcat but i have got this error

apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1  11 Sep 2018]
18-Jun-2019 18:20:46.933 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-80"]
18-Jun-2019 18:20:46.961 SEVERE [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-80]]
 org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-80]]
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:113)

Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
        at org.apache.catalina.connector.Connector.initInternal(Connector.java:996)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
        ... 12 more
Caused by: java.net.SocketException: Permission denied
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:461)

Please anyone help me how to start tomcat8 on port 80. I have above erroe after changing port inside server.xml

1

There are 1 best solutions below

0
Jonathan S. Fisher On

Port 80 is a privileged port. You have a few options:

  • Use a proxy like haproxy to bind to port 80 then forward to tomcat 8080
  • Use authbind to give permission to tomcat to bind to port 80
  • Use iptables kernel redirect from 80 to 8080

The second and third are [marginally] better performance since they happen in the kernel, but you'd only see any sort of latency or throughput increase in really really busy servers