ntyss
ntyss

Reputation: 101

Connecting to apache tomcat from outside

I'm new to these forums and I hope I don't ask a stupid question. I've seen answers to my problem several times on the net, but it never worked for me.

So basically I installed tomcat 8 on a Debian 8.1 distant server, and I would like to simply connect to that server. But when I try to connect to MY_SERVER_IP:8080 in my web browser, I get a "This site can’t be reached" message, instead of the "It works !" page that I should get.

When I type this code on my ssh software (Putty) :

telnet MY_SERVER_IP 8080
GET /

The server sends an html page, with somewhere written "If you're seeing this, you've successfully installed Tomcat. Congratulations!". So it really looks like my server was properly installed, but that I just can't access it from outside. We also checked which ports are open, using the ssh software, and the port 8080 is actually open for IPv6 addresses only...

I tried to remove the "address" attribute from the "Connector" tag in /opt/apache-tomcat-8.5.13/conf/server.xml, and I also tried to add address="0.0.0.0" to it. I tried to add JAVA_OPTS= $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses to the catalina.sh startup script, as well as writing it in a new TOMCAT_HOME/bin/setenv.sh script. None of this worked.

Is there a way to fix my issue ? Thanks in advance for your help.

EDIT : after I call the instruction netstat -pln, my ssh software returns this (some of it is in french so let me know if you need some translation):

Connexions Internet actives (seulement serveurs)
Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat        PID/Program name
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      15594/named
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      15624/sshd
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      15594/named
tcp6       0      0 :::8080                 :::*                    LISTEN      19285/java
tcp6       0      0 ::1:53                  :::*                    LISTEN      15594/named
tcp6       0      0 :::22                   :::*                    LISTEN      15624/sshd
tcp6       0      0 ::1:953                 :::*                    LISTEN      15594/named
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      19285/java
udp        0      0 127.0.0.1:53            0.0.0.0:*                           15594/named
udp6       0      0 ::1:53                  :::*                                15594/named
Sockets du domaine UNIX actives(seulement serveurs)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Chemin
unix  2      [ ACC ]     STREAM     LISTENING     16166    1/systemd           /run/systemd/private
unix  2      [ ACC ]     SEQPACKET  LISTENING     811      1/systemd           /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     815      1/systemd           /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     25198    1/systemd           /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     34670    1/systemd           /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     5612     1/systemd           /run/acpid.socket

So unless I'm mistaken, it looks like the server is listening only to IPv6 addresses on the port 8080.

EDIT 3 : I added the two JAVA_OPTS arguments about IP4 again, restarted my tomcat, reran the netstat, and did ps -ef | grep java. Here is the result :

root@ns397627:~# netstat -pln
Connexions Internet actives (seulement serveurs)
Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat        PID/Program name
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      2532/java
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      15594/named
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      15624/sshd
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      15594/named
tcp6       0      0 ::1:53                  :::*                    LISTEN      15594/named
tcp6       0      0 :::22                   :::*                    LISTEN      15624/sshd
tcp6       0      0 ::1:953                 :::*                    LISTEN      15594/named
udp        0      0 127.0.0.1:53            0.0.0.0:*                           15594/named
udp6       0      0 ::1:53                  :::*                                15594/named
Sockets du domaine UNIX actives(seulement serveurs)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Chemin
unix  2      [ ACC ]     STREAM     LISTENING     16166    1/systemd           /run/systemd/private
unix  2      [ ACC ]     SEQPACKET  LISTENING     811      1/systemd           /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     815      1/systemd           /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     25198    1/systemd           /run/lvm/lvmetad.socket
unix  2      [ ACC ]     STREAM     LISTENING     34670    1/systemd           /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     5612     1/systemd           /run/acpid.socket
root@ns397627:~# ps -ef | grep java
tomcat8   2532     1 99 10:15 ?        00:00:20 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses -Djava.endorsed.dirs=/usr/share/tomcat8/endorsed -classpath /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat8 -Dcatalina.home=/usr/share/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start
root      2557  2016  0 10:15 pts/4    00:00:00 grep java

Upvotes: 2

Views: 2733

Answers (1)

spacepickle
spacepickle

Reputation: 2788

For a default install of tomcat8 on debian jessie (8.7), you can force tomcat to use IPv4 addresses with the following in your setenv.sh file:

JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses"

Note the use of double quotes around the value part of the statement.

The following command will append to your current setenv.sh file in the correct location (remember to remove the original setenv.sh if you have JAVA_OPTS set there already)

echo 'JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses"' >> /usr/share/tomcat8/bin/setenv.sh

Upvotes: 1

Related Questions