trying to update host settings

May 1, 2015 1.3k views
Apache

I am trying to setup Apache to run on port 8080 but I do not see the entries suggested how can I add them I have run sudo nano /etc/apache2/ports.conf

and this is what my file looks like
http://prntscr.com/7084yh

the tutorial says Find and change the following lines to have apache running on port 8080, accessible only from the localhost:

NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080

can I just add these lines to the ports.conf file ?

thanks
Mike

2 Answers

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

Thanks for clearing that up, maybe some of the tutorials should be updated to help us newbies out

thanks again

Mike

Have another answer? Share your knowledge.