注:针对一台服务器部署多个网站的应用(这里用的是比较常见的基于域名的虚拟主机)
实现:在同一台服务器上部署两个网站:
www.a.com
www.b.com
这里就展示一个www.b.com的部署
1.配置b.com
[root@centos7 ~]# vim /etc/httpd/conf.d/b.conf
# www.b.com的配置文件
<VirtualHost 192.168.101.128:80>
ServerName www.b.com
DocumentRoot /var/web/b.com
ErrorLog /var/log/httpd/b.com/error_log
CustomLog /var/log/httpd/b.com/access_log combined
<VirtualHost>
如果/var/web/这个目录没有做授权的话还需要做授权
也是在/etc/httpd/conf.d/b.conf,这个配置文件中,后面添加:
<Directory "/var/web/">
Allowoverride None
Require all granted
</Directory>
2.创建所需要的文件
[root@centos7 ~]# mkdir -p /var/web/b.com
[root@centos7 ~]# mkdir -p /var/log/httpd/b.com/
3.给b.com设置一个主页面:
[root@centos7 ~]# vim /var/web/b.com/index.html
<html>
hello,
welcome to b.com
</html>
4.检查配置文件的语法有没有问题:
[root@centos7 ~]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
5.语法没有问题就可以重启httpd了:
[root@centos7 ~]# systemctl restart httpd
重启了之后,在目录/var/log/httpd/b.com/这个目录下就会自动建好error_log和access_log这两个日志文件