Home >Operation and Maintenance >Linux Operation and Maintenance >Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously

Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously

小云云
小云云Original
2018-03-16 13:43:363253browse

Such a scenario; we have a server; but want to host multiple websites; then configuring a virtual host under Apache can meet this demand. The simpler configuration steps based on the host name are as follows:

Sample environment
ip: 115.28.17.191

Domain name:
baijunyao.com
thinkbjy.com

Directory:
/var/www/html/baijunyao
/var/www/html/thinkbjy

The desired effect is:
Visiting baijunyao.com points to /var/www/html/baijunyao
Visiting thinkbjy.com points to / var/www/html/thinkbjy

1: Modify hosts file

[root@iZ28qa8jt4uZ /]# ifconfig;              //查看ip并记录自己的ip地址

Bash

Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously

[root@iZ28qa8jt4uZ /]# vim /etc/hosts;                    //修改hosts文件 添加如下两行内容

Bash

115.28 .17.191 baijunyao.com
115.28.17.191 thinkbjy.com
Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously
2: Modify httpd.conf file

[root@iZ28qa8jt4uZ /]# vim /etc/httpd/conf/httpd.conf;     //修改httpd.conf文件 删除990行 NameVirtualHost *:80前的#注释

Bash

Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously
3: Modify the httpd-vhosts.conf file and set httpd-vhosts.conf as follows. If it does not exist, create a new one (do not use the httpd-vhosts.conf configuration that comes with the system)

[root@iZ28qa8jt4uZ /]# vim /etc/httpd/conf.d/virtual.conf;            //设置httpd-vhosts.conf如下 如没有则新建

Bash

<VirtualHost *:80>
        DocumentRoot /var/www/html/baijunyao
        ServerName baijunyao.com</VirtualHost><VirtualHost *:80>
        DocumentRoot /var/www/html/anlianma
        ServerName thinkbjy.com</VirtualHost>

Bash

Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously
The virtual host configuration ends here; just create a new html page in the corresponding directory for testing;
If you need to mount multiple sites and run them simultaneously in the local wamp environment, please refer to : Set up a local wamp environment to mount multiple sites to run simultaneously.

Related recommendations:

Apache configures multiple virtual hosts and localhost cannot access the solution, apachelocalhost_PHP tutorial

Multiple apache under windows Problems in the middle of virtual host_PHP tutorial

APACHE configures multiple domain names with the same IP, and configures multiple virtual hosts with the same IP under Apache_PHP tutorial

The above is the detailed content of Apache configures multiple virtual hosts under Linux to mount multiple sites and run them simultaneously. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn