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
[root@iZ28qa8jt4uZ /]# vim /etc/hosts; //修改hosts文件 添加如下两行内容
Bash
115.28 .17.191 baijunyao.com
115.28.17.191 thinkbjy.com
2: Modify httpd.conf file
[root@iZ28qa8jt4uZ /]# vim /etc/httpd/conf/httpd.conf; //修改httpd.conf文件 删除990行 NameVirtualHost *:80前的#注释
Bash
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
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:
Multiple apache under windows Problems in the middle of virtual host_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!