How do I make Apache Web Server listen on two different ports?

Solution 1:

A standard Debian install of apache will have the following fragment of configuration:

Listen 80

<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
</IfModule>

This is telling apache to listen on port 80 and to listen to port 443 if mod_ssl is configured. In your case you'd want:

Listen 80
Listen 8080

You need to make sure you run a restart, not a reload operation on apache for it to pay any attention to new Listen directives. The safest thing to do is to stop apache, make sure it is dead and start it again.

If this configuration does not work, check the log files for any error messages. You could use "netstat -lep --tcp" to see if there is anything listening on port 8080. Finally, if everything else doesn't work, try running apache under strace to see if it's trying to bind to that port and failing, but not logging the problem.

Solution 2:

These answers are great, but they leave out the possibility that Owen has actually done this already ("I've added Listen 8080") may mean exactly what it sounds like (i.e., what David has suggested).

If you have already done this and still find it not working, make sure that you have correctly configured your directives for each subdomain you may have, including the default one (if it's been configured manually to listen to :80 right after the name).

You probably have a directive like this:

<VirtualHost *:80>
 ServerName michaelsanford.com
 etc…
</VirtualHost>

You need to change that to <VirtualHost *:8080> or <VirtualHost *:*>.

Solution 3:

Step 1

#vi httpd.conf
Listen 80

<IfModule mod_ssl.c>
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
</IfModule>

httpd(apache) to listen on port 80 and to listen to port 443 if mod_ssl is configured.

Listen 80
Listen 8080

Step 2

#su - service httpd restart

Step 3

$ netstat -lntp

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:47027               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 192.168.1.1:80              0.0.0.0:*                   LISTEN      -                   
tcp        0      0 192.168.1.1:8080            0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -                   
tcp        0      0 ::ffff:127.0.0.1:45100      :::*                        LISTEN      3149/java           
tcp        0      0 :::111                      :::*                        LISTEN      -                   
tcp        0      0 :::80                       :::*                        LISTEN      -                   
tcp        0      0 :::57173                    :::*                        LISTEN      3149/java           
tcp        0      0 :::18197                    :::*                        LISTEN      3149/java           
tcp        0      0 :::22                       :::*                        LISTEN      -                   
tcp        0      0 ::1:631                     :::*                        LISTEN      -                   
tcp        0      0 :::40832                    :::*                        LISTEN      3149/java           
tcp        0      0 ::ffff:127.0.0.1:6880       :::*                        LISTEN      3149/java