Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to change the port used by a website from 80 to 8080.

Here is my /etc/apache2/ports.conf:

NameVirtualHost *:80
NameVirtualHost *:8080
Listen 80
Listen 8080

Here is my VirtualHost file:

<VirtualHost *:8080>
  # Admin email, Server Name (domain name), and any aliases

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/

netstat -lntp output:

tcp6       0      0 :::8080       :::*              LISTEN      7267/apache2    
tcp6       0      0 :::80         :::*              LISTEN      7267/apache2

When I restart apache using the port 8080 in my VirtualHost, the website goes down (could not connect to website error in chrome), if I change back to port 80, all works correctly again.

What am I doing wrong here?


The host it's a linode machine with Debian 7.

Also I do not have SElinux enabled.

The /etc/hosts config:   <> <serverhostname>   debian

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I think the port 8080 it's correctly open, here is the output of iptables -L -n -v:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  467 36136 ACCEPT     all  --  lo     *             
    0     0 REJECT     all  --  *      *            reject-with icmp-port-unreachable
 103K   11M ACCEPT     all  --  *      *              state RELATED,ESTABLISHED
  600 35296 ACCEPT     tcp  --  *      *              tcp dpt:80
   30  1532 ACCEPT     tcp  --  *      *              tcp dpt:443
   42  2308 ACCEPT     tcp  --  *      *              tcp dpt:8080
 6860  411K ACCEPT     tcp  --  *      *              state NEW tcp dpt:22
   44  2848 ACCEPT     icmp --  *      *             
  860 57824 LOG        all  --  *      *              limit: avg 5/min burst 5 LOG flags 0 level 7 prefix "iptables denied: "
  968 67687 DROP       all  --  *      *             

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  *      *             

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

curl -v http://localhost:8080 output:

* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* connected
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.26.0
> Host: localhost:8080
> Accept: */*
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 10 Jun 2013 09:58:08 GMT
< Server: Apache/2.2.22 (Debian)
< X-Powered-By: PHP/5.4.4-14
< X-Pingback:
< Location: http://localhost/
< Vary: Accept-Encoding
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
* Connection #0 to host localhost left intact
* Closing connection #0
share|improve this question
Are they...going to ? – Nathan C Jun 5 '13 at 14:35
No, it also won't work specifying the port in the url. – rfc1484 Jun 5 '13 at 14:54

Maybe Port 8080 is blocked by iptables. Use iptables -L -n -v to see if iptables is enabled and effectively blocking packets to port 8080.

share|improve this answer

what distro are you running? You may have SElinux enabled, which is denying your requests.

Check if SElinux is enbaled

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

If the current mode is enforcing try to disable it during troubleshooting:

#setenforce 0

If it's working now you have to create a custom SElinux policy via audit2allow.

share|improve this answer

From your netstat output it looks like port 8080 is listening on ipv6. Are you using ipv6 to connect?

Is httpd listening on ipv4?

Can you run netstat -lntp|grep 80 and show us all of the output instead of just pasting in the bit you think is relevant.

share|improve this answer
Running that netstat command returns only the two lines I've already posted. – rfc1484 Jun 10 '13 at 10:23
Looks like you are only listening on IPv6. Do you have IPv6 records for the server's name in DNS? Or maybe /etc/hosts? – Jason Tan Jun 10 '13 at 11:07
If you want to use IPv4 and you only have 1 IPv4 IP on the host then try replacing the VirtualHost and NameVirtualHost directives with that IP. Or turn off ipv6 if you are not really using it. – Jason Tan Jun 10 '13 at 11:09
If you look at your curl command above you will see it is connectiong on the IPv6 localhost. That(presumably) works, because that IPv6 IP (i.e. ::1 )is listening and is probably resolvable via /etc/hosts. So curl works because it is using ipv6. – Jason Tan Jun 10 '13 at 11:11
I use a standard linode configuration for the DNS, as explained here: I've updated the post with the complete hosts file. – rfc1484 Jun 10 '13 at 12:29

I suggest following workaround,

  • check apache configuration

    apachectl configtest

  • test the page from the server itself and check HTTP output

    wget -O - "localhost"

  • check apache error_log to what kind of error are you getting, probably a configuration on your website is not allowing port 8080

  • try use only port 8080 to see what happens

    NameVirtualHost *:8080 Listen 8080

  • create only a VirtualHost listening on port 8080

share|improve this answer

Ok, I see that port is open. What happend with

curl -v http://localhost:8080


share|improve this answer
As you could see your server returns header "Location: localhost/"; So your browser trying to fetch content from localhost, located at port 80. Is it a normal situation? Looks like there is a code, checking fqdn. Maybe you need to change any setting in site code. – dr-evil Jun 10 '13 at 10:15

I'm fairly certain your problem is that apache is listening on ipv6 at least for ::1 .

Can you please let me know if you want to use ipv4, ipv6 or both?

Please run the following and paste in the output:

ifconfig -a

That should show us all the IP addresses that are running on interfaces.

Assuming you are using http://<servername>.<> as the URL in chrome then please also run these commands are paste in the command and output:

dig <servername>.<>
dig <servername>
dig -t A <servername>.<>
dig -t A <servername>
dig -t AAAA <servername>.<>
dig -t AAAA <servername>

I'm assuming you want to use ipV4 not ipv6. If that is the case try this:

Change your /etc/hosts to look like this:  localhost <servername>.<> <servername>

# The following lines are desirable for IPv6 capable hosts
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

But replace the with your ipv4 address. Then restart apache. And try again with your browser and with curl.

With curl try localhost and <servername>.<>.

share|improve this answer

As per your curl test to localhost apache is listening to 8080 and responding although redirecting you with a 301 to http:// localhost/ but that seems to come from the default site.

As per your apache confing you are configuring a named virtual host, with ServerName


$ telnet localhost 8080
GET / HTTP/1.0

Ending with two line returns. If that is returning content it means that server configuration is working fine. So your problem is between you and your server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.