The ports.conf
file tells apache what ports to listen on for connections. The default is 80, but there are conditions for SSL if it’s enabled.
You can either add port 8080 or change from 80 to 8080.
Change the line
Listen 80
To this line
Listen 8080
If you use this syntax
Listen 127.0.0.1:8080
Then it tells apache to listen to port 8080
on interface 127.0.0.1
which is the localhost. That’s not what you want, because no one will be able to connect from outside. Just use Listen 8080
.
Now, that will only tell Apache to listen on that port. You need to also tell it what websites are accessible from that port.
$ cd /etc/apache2/sites-available
$ ls
All the files listed here are the available websites. Each file should reference a <VirtualHost>
that is configured for Apache.
You can control what port a virtual host will operate on, or you can use an *
to indicate all ports.
<VirtualHost *>
ServerName whathappentoday.com
ServerAlias www.whathappentoday.com
DocumentRoot /var/whathappentoday/web/www
<Directory /var/whathappentoday/web/www>
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.whathappentoday.log
CustomLog ${APACHE_LOG_DIR}/access.whathappentoday.log combined
</VirtualHost>
Other possible syntax is
<VirtualHost 127.0.0.1:8080>
Or
<VirtualHost *:8080>
Now, the NameVirtualHost
directive is a little ambiguous. This tells apache what ports support virtual hosts that have a ServerName
. I’ve never had to declare this directive to get named virtual hosts to work. If you want to declare the directive it would be like this, and put it in your apache2.conf
file (not the ports.conf
file).
NameVirtualHost *:8080
After you’ve made any changes to apache’s *.conf
files you have to restart the server.
$ service apache2 restart