RHEL7 配置http虛擬主機
一、安裝服務
通過yum的方式進行安裝,如果沒有配置,可以執行以下命令進行配置
[root@localhost ~]# cat > /etc/yum.repos.d/example.repo <<EOF
> [example]
> name=example
> baseurl=file:///mnt
> enabled=1
> gpgcheck=0
> EOF
yum安裝能解決軟件包之間的依賴關係
[root@localhost ~]# yum -y install httpd
二、設置服務開機自動啓動
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
三、創建網站存放路徑
[root@localhost ~]# mkdir -p /www/qingshan
[root@localhost ~]# echo "青山如是" > /www/qingshan/index.html
四、創建虛擬主機配置文件
[root@localhost ~]# mkdir /etc/httpd/vhost-conf.d/
[root@localhost ~]# echo "Include vhost-conf.d/*.conf" >> /etc/httpd/conf/httpd.conf
上面兩步操作分別是創建了虛擬主機配置文件路徑,並把虛擬主機的配置文件路徑添加到httpd的配置文件路徑中
創建配置文件
[root@localhost ~]# vim /etc/httpd/vhost-conf.d/vhost-name.conf
<VirtualHost *:80>
ServerName www.qingshan.com
DocumentRoot /www/qingshan/
</VirtualHost>
<Directory /www/qingshan/>
Require all granted
</Directory>
五、驗證訪問
修改本地hosts文件
[root@localhost ~]# echo "127.0.0.1 www.qingshan.com" >> /etc/hosts
打開瀏覽器訪問