How to host multiple websites on a Apache Linux web server?

I have a Linux web server with Apache (httpd). How to host multiple websites on Apache?

asked Jul 6, 2015 by anonymous

1 Answer

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.

answered Jul 6, 2015 by Eric Z Ma (43,500 points)
edited Jul 6, 2015 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...