52

I'd like an Apache Web Server I have installed at home to listen on port 80 and port 8080.

I've added Listen 8080 to httpd.conf and restarted the Apache services but the server doesn't seem to be listening on 8080. Punching in http://localhost:8080 times out and doesn't display my index.html but http://localhost will display my index.html.

How do I make it listen to 80 and 8080?

Owen
  • 633
  • 1
  • 5
  • 8
  • Why do you think it's not listening on port 8080? It might also be useful to post snippets of your configuration. – David Z Jun 18 '09 at 15:12
  • 1
    Did you restart Apache after editing the http.conf? – Dana the Sane Jun 18 '09 at 15:41
  • @David I've updated my question to show why I think it's not listening on 8080. Don't have access to httpd.conf right now. @Dana - yes. – Owen Jun 18 '09 at 16:19

7 Answers7

73

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.

David Pashley
  • 23,497
  • 2
  • 46
  • 73
8

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 *:*>.

msanford
  • 1,477
  • 15
  • 28
  • I suspect this is my problem. I think do have a directive. I'll have to check this. – Owen Jun 18 '09 at 16:22
  • 1
    If you don't have a virtual host, you'll be served content from the global DocumentRoot, which will probably either give you a standard index.html, a directory index page, a 404 or a 403 error. It wouldn't timeout. – David Pashley Jun 18 '09 at 18:33
  • 2
    Sounds like you have a firewall in place that's dropping packets silently. – msanford Jun 19 '09 at 11:31
  • As it turns out, it was a firewall issue. – Owen Jun 22 '09 at 10:41
6

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       
Mei
  • 4,590
  • 8
  • 45
  • 53
Rajat
  • 3,349
  • 22
  • 29
0

In case someone using Windows and trying to add a different port, then we should update the ServerName also. Default, ServerName is set to localhost:80.

Listen 80
Listen 8080

ServerName localhost
Rashid
  • 101
  • 1
0

You may need to configure a site a port 8080 for this to work. Read through the documentation for Apache Virtual Hosts. Each 'site' can be set up to accept connections on specific ports (and ip's, etc). Does you have a virtual host in your http.conf that is only configured for port 80?

Also, you can confirm that the server is listening on 8080 using netstat -nlp and looking for an entry on that port.

Dana the Sane
  • 828
  • 10
  • 19
  • 1
    No, this isn't right. If you want apache to listen on a port, you need to use the Listen directive. – David Pashley Jun 18 '09 at 15:06
  • Check http://httpd.apache.org/docs/2.2/en/vhosts/examples.html#port – radius Jun 18 '09 at 15:11
  • 1
    Well, it might be somewhat right - many people create vhosts like , and in that case you would need to change it to or create another vhost for port 8080. (Of course, the Listen directive is also required) – David Z Jun 18 '09 at 15:11
  • 1
    @David Pashley, The author stated that the Listen directive had already been added. – Dana the Sane Jun 18 '09 at 15:27
0

You may also want to check to see if you have SELinux enabled. The default SELinux configuration may not allow you to run Apache on non-standard ports. Here's a site that shows you if you are running SELinux and how to disable it, if you don't want or use its features. http://www.crypt.gen.nz/selinux/disable_selinux.html

  • Or you could leave SELinux on, if you are on a modern SELinux system see how the ports are labeled with a semanage port -l. see http://danwalsh.livejournal.com/9275.html which is titled "I want my apache daemon to listen on a different port but SELinux is preventing it, What do I do?" – rev Jul 29 '09 at 21:49
0

Assuming linux run netstat -lntp as root as you can see if apache is listening on 8080 or not. This will help you identify if the problem is apache not listening or if there are factors external (e.g. firewall, selinux etc) to apache making the connection time out.

Jason Tan
  • 2,752
  • 2
  • 17
  • 24