分享

centos7下apache2.4.6虚拟主机配置

 醉人说梦 2018-04-27

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
  • 1

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多