Apache2 and Virtual Host with IP-Based (port)

The one feature of Apache2 is Virtual host , The virtual host have many type such as Name-based, IP-based and this one solution to use 1 IP Address and configure each port for each site.  (By default http is run on port 80)

Existing

  1. IP : 192.168.1.10
  2. Have 2 website in /var/www/a and /var/www/b (log file of site b contain in /var/www/b/log)

Solution

1. Edit file ports.conf to listen 8080 port.

nano /etc/apache2/ports.conf

And add this line at the bottom.

Listen 8080

2. Create virtual site.

nano /etc/apache2/site-availables/b

And add this text

<VirtualHost *:8080>
DocumentRoot /var/www/b
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/b>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/b/log/error.log
LogLevel Warn
</VirtualHost>

3. Enable virtual site.

a2ensite b

4. Restart apache.

invoke-rc.d apache2 restart

5. Try to access your website with

http://192.168.1.10:8080

ball Written by:

Teerapat Khunpech Live, Tech, Beers, Bike, Cafe Racer, Docker, Devops, Eco-System