Change Apache2 HTTP Default Port on Ubuntu 16.04 | 17.10 | 18.04

Apache2, the most popular HTTP server in use today is easy to manage and configure… It is a HTTP server, but can be served as a proxy server and more.

Sometimes you’ll want Apache2 to listen and communicate over not its default port, but a different port instead… when you want to do that, the steps below can be a good starting point..

For example, if you want Apache2 HTTP server to sit behind a proxy server, then the proxy server must be configured to listen on the default port 80… in this case, Apache2 must also be configured to listen on a different port then 80…, since two services can’t be assigned one port to listen on… there would be contentions..

This tutorial is going to show students and new users how to easily switch Apache2 default port from 80 to something else… like 8082.. in this way, other services can use port 80 to communicate..

When you’re ready to make this change, continue below:

Step 1: Identifying Apache2 Port Config File

To change Apache2 default port number, you need to look in two areas… the first is Apache2 /etc/apache2/ports.conf file.. In that file is where you configure the global port number.

The other location is in the /etc/apache2/site-available/ directory… each site configuration file there will have port number assigned… By default, the 000-default.conf file is configured to listen on port 80 while default-ssl.conf is configured to listen on 443

These are the locations you can change Apache2 default port numbers

sudo nano /etc/apache2/ports.conf
sudo nano /etc/apache2/sites-available/000-default.conf
sudo nano /etc/apache2/sites-available/default-ssl.conf

Step 2: Changing Apache2 Port Number

Now that you’ve identified the files you can change Apache2 port number, continue below to begin making those changes… for this port, we’ll change the default port 80 to 8082 and port 443 to 444.

First, run the commands below to open the port.conf file…

sudo nano /etc/apache2/ports.conf

Then change the Listen line from 80 to 8082

Listen 8082

Save the file and exit.

Next, open Apache2 default site configuration file and change the port from 80 to 8082

sudo nano /etc/apache2/sites-available/000-default.conf

Then change the VirtualHost directive in the file header from 80 to 8082

<VirtualHost *:8082>

Then save the file and exit.

Finally, open Apache2 default SSL site configuration file and change the port from 443 to 444

sudo nano /etc/apache2/sites-available/default-ssl.conf

Then change the port from 443 to 444

<VirtualHost default:444>

Save the file and exit..

Step 3: Restart Apache2

Now that you’ve changed the port number in all the files, run the commands below to restart apache2..

sudo systemctl restart apache2.service

After that, Apache2 service will begin listening on the port you assigned above…

That’s it! This is how one changes Apache2 port numbers.

You may also like the post below:

5 Replies to “Change Apache2 HTTP Default Port on Ubuntu 16.04 | 17.10 | 18.04”

  1. If you do not face any errors while restarting the Apache daemon, Congratulations! The Apache ports are now updated and Apache will listen for HTTP and HTTPS requests on the new ports that we have specified in our

  2. Its not listening on the new port

    I have tried these steps on AWS Ubuntu Linux 18.04

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.