This is the 11th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021

It took two days to finally do it. There are three changes that need to be made to enable access to the Internet.

Note: Make sure your server is not connected to a network through a router. If so, configure the router for forwarding.

1. Modify the /conf/server. XML file in the tomcat directory

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
Copy the code

Change the port field to an open port, or you can change it to 80, so you don’t have to add a port number for access, but remember to open port 80. I didn’t make any changes here.

Make sure the port is open.

Modify the tomcat/conf/server. XML file

  <Engine name="Catalina" defaultHost="localhost">


  <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
Copy the code

Change localhost to your IP address. Ubuntu can use ifconfig

If your IP address is assigned by a router, you need to configure the router to forward the IP address

3. The most important thing!

Baidu to the majority of the answer basically to the above step ended. If you are so lucky and successful, this step will not be necessary. But mine didn’t work. I did a search on Stacoverflow. The reason for this failure is that the JVM is not listening for IPv4 addresses and therefore cannot access them. So we need to modify the following two places.

Modify the /bin/catalina.sh and startup.sh files in the tomcat directory. Add the following sentence.

JAVA_OPTS= $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses
Copy the code

Mine is already accessible with these two sentences

If your server is running Windows, you need to modify the. Bat files

4. If the access is still unavailable

If you have all the above configured and cannot access it yet, if you happen to be running Ubuntu, you can try the following methods. Install authbind.

apt-get install authbind
Copy the code

Example Modify the /etc/default/tomcat7 file.

Modified to

AUTHBIND=yes
Copy the code

If you can’t access it again after the restart, try to see if you can access the Internet, or if you are using a router and have no forwarding configuration, or if the port is not open.

5. Aliyun Ubuntu image port 80 cannot be accessed

By default, only the root user can access the port below 1024 in the Ubuntu image of Aliyun server. Therefore, if these are configured and still cannot access, you are advised to start Tomcat as the root user or change the port. Then (I) or (no) add routing rules to forward port 80 to other ports