Multiple Apache Sites on Different Port Numbers


Hosting multiple websites on a Linux server with apache using different ports for each


Before – buy Linux hosting package… IONOS
Listen for ports 80, 8080 and direct to specific website folders.
Find IP address
Find ports
Setup website folders

Quick guide

Create website, create/enable config, enable port

nano cd /var/www/
Hello World from domain1

nano etc/apache2/sites-enabled/site1.conf
DocumentRoot /var/www/

a2dissite 000-default.conf
a2ensite site1.conf
systemctl reload apache2

Part 0 – Info

ports 1-1024 = reserved
ports 1025-65535 = free

port 80 = website1
port 8080 = website2

Сommands used:

cd // change directory + cd .. to go back
nano // edit file
ip addr show // show private and public IP address
cat * // show all files contents
a2dissite // apache disable site config
a2ensite // apache enable site config
systemctl reload apache2 // reload apache web server


etc/apache2/sites-enabled/ // Virtual Hosts directory
etc/apache2/ports.conf // Public ports
var/www/ // Website folders

Part 1 – Diagnostics

  1. Find address for domain to connect to
ip addr show

![[Pasted image 20231205173824.png]]

This shows the IP address you will need for the browser to connect to your website.

  1. Find open ports
ss -nat

![[Pasted image 20231205175025.png]]

“:80” = This shows port 80 is Listening for requests from the browser

Part 2 – Website folders

  1. Make sure files are in directories (using FileZilla or commands)
    ![[Pasted image 20231205174355.png]]
cd /var/www/
nano cd /var/www/
Hello World from domain1

cd /var/www/
nano cd /var/www/
Hello World from domain2
  1. Use browser to connect to IP address

Part 3

(Hint – shortcut)

Add to top of Virtual Hosts configurations files:
Listen 80
Listen 8080

  1. Show and edit Virtual Hosts configuration files
cd etc/apache2/sites-enabled/
cat *

![[Pasted image 20231205180200.png]]

nano etc/apache2/sites-enabled/site1.conf
nano etc/apache2/sites-enabled/site2.conf

Change “DocumentRoot” to your website folder
Change VirtualHost port of site2 to 8080

  1. Disable default VirtualHosts config and enable new configs
a2dissite 000-default.conf
a2ensite site1.conf
a2ensite site2.conf
  1. Edit ports (don’t need if used shortcut)
nano etc/apache2/ports.conf

Add to file:
Listen 80
Listen 8080

  1. Check ports are working
systemctl reload apache2
ss -nat
  1. Enable ports on server
  2. Go to website


Leave a Reply

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