centos7.3 利用yum安装apache2.4配置多虚拟目录

centos7.3 利用yum安装apache2.4配置多虚拟目录,配置id禁止访问站点,apache启动,apache关闭,apache重启,apache设置开机启动

安装apache

# yum install httpd
# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
# yum install httpd -y
Loaded plugins: fastestmirror
…………………………………………………………………………
Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-45.el7.centos                         mailcap.noarch 0:2.1.41-2.el7                        

Complete!

启动apache

# systemctl start httpd.service

配置apache

修改前备份文件

# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

配置httpd文件

因为在apache2.4中变化挺大,和nginx一样,可以自定义.conf文件。
在主配置文件中启用虚拟主机

# mkdir /etc/httpd/vhost.d/   //创建一个存放虚拟目录的配置文件
# vim /etc/httpd/conf/httpd.conf //在最后一行加上 include vhost.d/*.conf

虚拟主机配置文件

# vim /etc/httpd/vhost.d/default.conf
//禁止用ip地址从网站根目录开始访问
<VirtualHost *:80>
        DocumentRoot /var/www/html
        ServerName 127.0.0.1
        <Location />
                Order Allow,Deny
                Deny from all
        </Location>
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /var/www/html/test.com
        ServerName test.com
        ServerAlias www.test.com
</VirtualHost>

测试配置文件是否正确

# /sbin/service httpd configtest
Syntax OK

重新启动apache服务

# systemctl restart httpd.service

备注

# systemctl start httpd.servcie //启动
# systemctl stop httpd.service //停止
# systemctl restart httpd.service //重启
# apachectl restart  //重启
# systemctl enable httpd.service //设置开机启动

 

发表评论

评论已关闭。

相关文章

猜你喜欢