Task
Hosting multiple websites on a Linux server with apache using different ports for each
Description
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/domain1.com/public_html/index.html
Hello World from domain1
nano etc/apache2/sites-enabled/site1.conf
DocumentRoot /var/www/domain1.com/public_html/
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
Directories:
etc/apache2/sites-enabled/ // Virtual Hosts directory
etc/apache2/ports.conf // Public ports
var/www/domain1.com/public_html // Website folders
Part 1 – Diagnostics
- 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.
- 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
- Make sure files are in directories (using FileZilla or commands)
![[Pasted image 20231205174355.png]]
cd /var/www/domain1.com/public_html
nano cd /var/www/domain1.com/public_html/index.html
Hello World from domain1
cd /var/www/domain2.com/public_html
nano cd /var/www/domain2.com/public_html/index.html
Hello World from domain2
- Use browser to connect to IP address
http://85.215.59.9:80/
Part 3
(Hint – shortcut)
Add to top of Virtual Hosts configurations files:
Listen 80
Listen 8080
- 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
- Disable default VirtualHosts config and enable new configs
a2dissite 000-default.conf
a2ensite site1.conf
a2ensite site2.conf
- Edit ports (don’t need if used shortcut)
nano etc/apache2/ports.conf
Add to file:
Listen 80
Listen 8080
- Check ports are working
systemctl reload apache2
ss -nat
- Enable ports on server
Ionos… - Go to website
http://85.215.59.9:80/
http://85.215.59.9:8080/
DONE