In this tutorial you will learn how to setup multiple virtual hosts listening on the same custom port in Apache. You will learn how to create 4 different virtual hosts: 2 using the default :80 port and 2 using the custom :8000 port using the “Listen” and “Include” Apache directives.
Code used during this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# Apache Multiple virtual hosts listening on the same custom port # Create "wp.liviubalan.com-8000.conf" virtual host conf cd /etc/apache2/sites-available/ sudo cp http.liviubalan.com-8000.conf wp.liviubalan.com-8000.conf sudo vi wp.liviubalan.com-8000.conf ServerName wp.liviubalan.com ServerAlias www.wp.liviubalan.com DocumentRoot /var/www/wp.liviubalan.com-8000 ErrorLog /var/log/apache2/wp.liviubalan.com-8000-error.log CustomLog /var/log/apache2/wp.liviubalan.com-8000-access.log combined <Directory "/var/www/wp.liviubalan.com-8000/"> # Create DocumentRoot dir mkdir /var/www/wp.liviubalan.com-8000 echo "Hello from wp.liviubalan.com:8000" > /var/www/wp.liviubalan.com-8000/index.php # Enable virtual host file sudo a2ensite wp.liviubalan.com-8000.conf # Restart Apache sudo service apache2 restart # Overlapping Listen directives will result in a fatal error which will prevent the server from starting up. # Address already in use: AH00072: make_sock: could not bind to address [::]:8000 sudo vi /etc/apache2/sites-available/global.conf #Listen 80 Listen 8000 # Includes other configuration files from within the server configuration files # :80 Include /etc/apache2/sites-available/http.liviubalan.com.conf Include /etc/apache2/sites-available/wp.liviubalan.com.conf # :8000 Include /etc/apache2/sites-available/http.liviubalan.com-8000.conf Include /etc/apache2/sites-available/wp.liviubalan.com-8000.conf # Disable Apache virtual hosts sudo a2dissite http.liviubalan.com sudo a2dissite wp.liviubalan.com sudo a2dissite wp.liviubalan.com-8000.conf sudo a2dissite http.liviubalan.com-8000.conf sudo a2dissite liviubalan.ro.conf sudo a2dissite 000-default.conf # Enable Apache virtual host sudo a2ensite global.conf ls -al /etc/apache2/sites-enabled/ # Restart Apache sudo service apache2 restart sudo vi /etc/apache2/sites-available/http.liviubalan.com-8000.conf sudo vi /etc/apache2/sites-available/wp.liviubalan.com-8000.conf #Listen 8000 # Browser http://http.liviubalan.com/ http://http.liviubalan.com:8000/ http://wp.liviubalan.com/ http://wp.liviubalan.com:8000/ # Useful links https://httpd.apache.org/docs/2.4/vhosts/examples.html https://httpd.apache.org/docs/2.2/en/mod/core.html#include |
Useful links:
https://httpd.apache.org/docs/2.4/vhosts/examples.html
https://httpd.apache.org/docs/2.2/en/mod/core.html#include