How to host multiple websites on a Apache Linux web server?
Posted on In QAI have a Linux web server with Apache (httpd). How to host multiple websites on Apache?
To host websites www.example1.com and www.example2.com on a single node with Apache2 on a single IP, you can use VirtualHost as follows.
Edit /etc/httpd/conf/httpd.conf
and add the following lines:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/example1.com
ServerName www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example2.com
ServerName www.example2.com
# Other directives here
</VirtualHost>
Then you can store your websites under the corresponding directory specified with DocumentRoot for each domain.
After restarting Apache2 by # apachectl restart
or # systemctl restart httpd.service
or # service httpd restart
or other distro specific commands, each domain (point to the web server) will be in each own’s directory.
Note that www.example1.com and example1.com are two different domains and you will need to set up two virtual hosts if you want to use both.