1,/etc/httpd/conf.d 目录下新增 vhost.conf,添加内容如下:
<VirtualHost *:80>
#绑定的主域
ServerName centos7.xxx.com
#绑定的子域名
ServerAlias localhost
#网站主目录
DocumentRoot /var/www/html/
#日志配置
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log common
#ServerSignature Off
</VirtualHost>
#测试一的配置
<Directory "/var/www/html/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
#绑定的主域
ServerName test.com
#绑定的子域名
ServerAlias www.test.com
#网站主目录
DocumentRoot /home/website/com.test.www/
#日志配置
ErrorLog /home/web_log/com.test.www_error.log
CustomLog /home/web_log/com.test.www_access.log common
#ServerSignature Off
</VirtualHost>
#测试一的配置
<Directory "/home/website/com.test.www/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
2,确认apache的主配置文件(/etc/httpd/conf/httpd.conf)的下述配置项:
Include conf/extra/httpd-vhosts.conf
3,/etc/hosts 新增 127.0.0.1 test.com www.test.com
4,设置selinux,使得apache有合适的对脚本和日志的操作权限:
chcon -R -t httpd_sys_content_t /home/website/com.test.www
chcon -R -t httpd_log_t /home/web_log
(ps:ls -Zl 可查看目录或档案的selinux权限)
5,检测配置文件正确性:apachectl configtest
6,重启apache:systemctl restart httpd
|