CentOS configure the virtual host virtualhost to enable the server to support multiple web sites with multiple domain names

  • 2020-05-17 07:14:40
  • OfStack

The example in this article describes how CentOS configured the virtual host virtualhost to enable the server to support multiple web sites and multiple domain names. I will share it with you for your reference as follows:

How to let centos (redhat) configure the virtual host, allow the server to support multiple sites, for Apache, only need you to modify the apache configuration file/etc/httpd/conf/httpd conf can.

There is an example file, you just need to configure it.


#<VirtualHost *:80>
#  ServerAdmin webmaster@dummy-host.example.com
#  DocumentRoot /www/docs/dummy-host.example.com
#  ServerName dummy-host.example.com
#  ErrorLog logs/dummy-host.example.com-error_log
#  CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHos>

You can refer to my configuration and add at the bottom of httpd.conf:


NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html
ServerName www.yourweb.com
#ErrorLog /var/log/httpd/yourweb/error_log
# Note that I've set up a production log in days 
ErrorLog "|rotatelogs /var/log/httpd/yourweb/error_log%Y_%m_%d.log 86400 480"
#CustomLog /var/log/httpd/yourweb/access_log common
CustomLog "|rotatelogs /var/log/httpd/yourweb/access_log%Y_%m_%d.log 86400 480" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/blog
ServerName blog.yourweb.com
ErrorLog /var/log/httpd/blog/error_log
CustomLog /var/log/httpd/blog/access_log common
</VirtualHost>

As mentioned above, I configured two virtual hosts: the domain name is www.yourweb.com blog.yourweb.com

Note that it does not take effect until apache is restarted (service httpd restart)

I hope this article has helped you with CentOS server management.


Related articles: