1,/etc/httpd/conf.d 目录下新增 vhost.conf,添加内容如下:
<VirtualHost *:80>#绑定的主域ServerName centos7.xxx.com#绑定的子域名ServerAlias localhost#网站主目录DocumentRoot /var/www/html/#日志配置ErrorLog /var/log/httpd/error.logCustomLog /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.logCustomLog /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>
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
联系客服