53

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?

3
  • 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, 2009 at 15:12
  • 1
    Did you restart Apache after editing the http.conf? Jun 18, 2009 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, 2009 at 16:19

7 Answers 7

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.

3
  • 1
    In Apache 2.4 where can this configuration fragment be found? Thanks. Sep 18, 2015 at 11:52
  • 5
    Answering my own question: /etc/apache2/ports.conf. Sep 18, 2015 at 14:53
  • where to do that in wondows -> xampp -> htdocs folder??? Dec 17, 2020 at 13:56
9

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

4
  • I suspect this is my problem. I think do have a <VirtualHost *:80> directive. I'll have to check this.
    – Owen
    Jun 18, 2009 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. Jun 18, 2009 at 18:33
  • 2
    Sounds like you have a firewall in place that's dropping packets silently.
    – msanford
    Jun 19, 2009 at 11:31
  • 1
    As it turns out, it was a firewall issue.
    – Owen
    Jun 22, 2009 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       
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

1
  • 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 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, 2009 at 21:49
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.

4
  • 1
    No, this isn't right. If you want apache to listen on a port, you need to use the Listen directive. Jun 18, 2009 at 15:06
  • 1
    Well, it might be somewhat right - many people create vhosts like <VirtualHost *:80>, and in that case you would need to change it to <VirtualHost *:*> or create another vhost for port 8080. (Of course, the Listen directive is also required)
    – David Z
    Jun 18, 2009 at 15:11
  • 1
    @David Pashley, The author stated that the Listen directive had already been added. Jun 18, 2009 at 15:27
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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .