Apache doesn't listen on all ports configured with virtual host and reverse proxy

Tibor Nagy asked:

I have a host (Ubuntu 16.04) and a virtual machine on it. I want to use apache to forward different ports to the VM with the reverse proxy modul. The problem is, that apache doesn’t listen on all configured ports.

I have the following settings in /etc/apache2/sites-enabled/moni1.softxs.ch:

<VirtualHost *:80>
    ServerName          moni1.softxs.ch
    Redirect            301 / https://moni1.softxs.ch/
</VirtualHost>

<VirtualHost *:443>
    ServerName          moni1.softxs.ch
    ProxyPreserveHost   On
    ProxyRequests       Off
    ProxyPass           / http://172.16.3.101:80/ retry=0
    ProxyPassReverse    / http://172.16.3.101/
    SSLCertificateFile /etc/letsencrypt/live/moni1.softxs.ch/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/moni1.softxs.ch/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateChainFile /etc/letsencrypt/live/moni1.softxs.ch/chain.pem
</VirtualHost>

<VirtualHost *:3000>
    ServerName          moni1.softxs.ch
    ProxyPreserveHost   On
    ProxyRequests       Off
    ProxyPass           / http://172.16.3.101:3000/ retry=0
    ProxyPassReverse    / http://172.16.3.101/
</VirtualHost>

<VirtualHost *:3010>
    ServerName          moni1.softxs.ch
    ProxyPreserveHost   On
    ProxyRequests       Off
    ProxyPass           / http://172.16.3.101:3010/ retry=0
    ProxyPassReverse    / http://172.16.3.101/
</VirtualHost>

I can see with netstat, that apache doesn’t listen on port 3010. No idea, why.

$ netstat -nlptu | grep apache2
tcp6       0      0 :::80                   :::*                    LISTEN      32252/apache2   
tcp6       0      0 :::3000                 :::*                    LISTEN      32252/apache2   
tcp6       0      0 :::443                  :::*                    LISTEN      32252/apache2 

The port is free, I can listen on it with nc. All other reverse proxy setting are working as expected.

My answer:


Somewhere in your Apache configuration, you must have matching Listen directives for each port you want to listen to:

 Listen 3000
 Listen 3010

It appears that you already have one, but not the other.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.