Search code examples
apache2ubuntu-14.04netstat

Problems with getting port open for apache2


On my server I have both a tomcat7 and an apache2 installed. I stopped the tomcat7 service and want to listen to with apache2 on port 80 (also tried for test with 8082) and port 443 (and tested also with 442). Before I stopped tomcat7 I tried it with 8082 and I could establish webside call and got the webside. But after I stopped tomcat7 and want to listen with apache2 to the ports 80 and 443 I could not establish a webside call (also not again if i tried it again with 8082 and 442).

A netstat –tulpe returned the following:

tobias@<hostname>:/etc/apache2$ netstat -tulpe
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 <hostname>.stratoser:8082 *:*                     LISTEN      root       <number>  -               
tcp        0      0 *:ssh                   *:*                     LISTEN      root       <number> -               
tcp        0      0 localhost:smtp          *:*                     LISTEN      root       <number> -               
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      root       <number> -               
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      root       <number> -               
tcp6       0      0 [::]:https              [::]:*                  LISTEN      tomcat7    <number> -               
tcp6       0      0 localhost:8005          [::]:*                  LISTEN      tomcat7    <number> -               
tcp6       0      0 [::]:http               [::]:*                  LISTEN      tomcat7    <number> - 

My ports.conf:

tobias@<hostname>:/etc/apache2$ cat ports.conf 
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8082

<IfModule ssl_module>
    Listen 442
</IfModule>

<IfModule mod_gnutls.c>
    Listen 442
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

and the 000-default.conf

tobias@<hostname>:/etc/apache2$ cat sites-available/000-default.conf 
<VirtualHost _default_:8082>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

a service –status-all returned:

[ + ]  apache2
[ - ]  tomcat7

The error log shows:

[Sun Jun 19 08:08:09.325184 2016] [core:notice] [pid 18254:tid 139964856280960] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jun 19 08:08:21.312066 2016] [mpm_event:notice] [pid 18254:tid 139964856280960] AH00491: caught SIGTERM, shutting down
[Sun Jun 19 08:09:47.916405 2016] [mpm_event:notice] [pid 18466:tid 140331437791104] AH00489: Apache/2.4.7 (Ubuntu) configured -- resuming normal operations
[Sun Jun 19 08:09:47.916530 2016] [core:notice] [pid 18466:tid 140331437791104] AH00094: Command line: '/usr/sbin/apache2'

(It seems that this lines are only warnings?)

I tried on the terminal of the server a wget and got the right answere both with:

tobias@<hostname>:~$ wget http://<server-ip>:8082
--2016-06-19 08:21:38--  http://<server-ip>:8082/
Connecting to <server-ip>:8082... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11510 (11K) [text/html]
Saving to: ‘index.html’

100%[====================================================================================>] 11.510      --.-K/s   in 0s      

2016-06-19 08:21:38 (370 MB/s) - ‘index.html’ saved [11510/11510]

and the sameanswere with the servername. But not on a webbrowser on an other machine. Why not?

BTW: A lsof -i returned noting. Why not?

Server version: Ubuntu, 14.04.4 LTS


Solution

  • You have provided all the right troubleshooting tools, thank you! One recommendation: omit the e argument from the netstat - for this type of troubleshooting, you want the numerical port numbers, not the translations into human-readable form. The p argument also does nothing if you are not root, but it doesn't hurt, either.

    The key to solving your problem is the netstat output. Your netstat output shows that Apache is listening on port 8082, but not on port 442. In your configuration, you also have not provided any SSL configuration (the 000-default.conf does not mention any SSL configuration options), so most likely it is simply not configured. So that explains the port 442 issue.

    The second thing the netstat output shows is that Apache is listening on port 8082, but only on one particular IP address. Since your wget succeeds, that is probably the correct one, it is just a unusual issue (and could potentially cause issues down the road if your network configuration changes).

    The last problem you mention is that you cannot reach the server from any other system. On that, none of your config files give a clue, but usually, this type of problem is that you did not open port 8082 in your firewall.

    One more aside: instead of using wget for testing, I'd initially use telnet. Because telnet is lower level, there are fewer moving parts that could interfere with your test. That's just a general tip, though - in this case, wget did give you the information you needed.