centos7 安装Apache2.4配置多站点目录

安装apache

 
  1. $ yum install httpd -y

启动apache

 
  1. $ systemctl start httpd.service

查看是否开启成功

 
  1. [root@centos7-1 ~] $ ps -ef|grep httpd
  2. root 1739 1 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  3. apache 1740 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  4. apache 1741 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  5. apache 1742 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  6. apache 1743 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  7. apache 1744 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  8. root 1749 1112 0 18:37 pts/0 00:00:00 grep --color=auto httpd

查看apache端口

 
  1. $ netstat -lntup|grep httpd

修改hosts解析

 
  1. $ vi /etc/hosts

改成如下内容

 
  1. 192.168.56.101 centos7.com www.centos7.com bbs.centos7.com blog.centos7.com

测试访问

 
  1. $ curl www.centos7-1.com

配置apache

备份文件

 
  1. $ cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.back

配置httpd文件

因为在apache2.4中变化挺大,和nginx一样,可以自定义.conf文件。

在主配置文件中启用虚拟主机

 
  1. $ mkdir /etc/httpd/vhost.d/
  2. $ echo "include vhost.d/*.conf"
  3. $ tail -1 /etc/httpd/conf/httpd.conf

配置多站点目录

 
  1. $ vi /etc/httpd/vhost.d/name.conf

写入下面的内容

 
  1. <VirtualHost *:80>
  2. ServerAdmin admin@amsilence.com
  3. DocumentRoot "/var/html/www"
  4. ServerName www.centos7.com
  5. ErrorLog "/var/httpd/logs/www-error_log"
  6. CustomLog "/var/httpd/logs/www-access_log" common
  7. </VirtualHost>
  8. <Directory /var/html/www/>
  9. Require all granted
  10. </Directory>
  11. <VirtualHost *:80>
  12. ServerAdmin admin@amsilence.com
  13. DocumentRoot "/var/html/bbs"
  14. ServerName bbs.centos7.com
  15. ErrorLog "/var/httpd/logs/bbs-error_log"
  16. CustomLog "/var/httpd/logs/bbs-access_log" common
  17. </VirtualHost>
  18. <Directory /var/html/bbs/>
  19. Require all granted
  20. </Directory>
  21. <VirtualHost *:80>
  22. ServerAdmin admin@amsilence.com
  23. DocumentRoot "/var/html/blog"
  24. ServerName blog.centos7.com
  25. ErrorLog "/var/httpd/logs/blog-error_log"
  26. CustomLog "/var/httpd/logs/blog-access_log" common
  27. </VirtualHost>
  28. <Directory /var/html/blog/>
  29. Require all granted
  30. </Directory>

重启Apache服务

 
  1. $ systemctl restart httpd.service

测试web访问

 
  1. [root@centos7-1 httpd] $ for name in www bbs blog;do curl $name.centos7.com;done;
  2. http://www.centos7.com
  3. http://bbs.centos7.com
  4. http://blog.centos7.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值