通过域名方式的HTTP

  1. 1 mkdir /www/129 //创建网站根目录
    2 vim /www/129/index.html //编辑网站默认网页
    小胖,你咋这么胖呢!
    3 vim /etc/httpd/conf.d/vhosts.conf //编辑配置文件
    Directory /www>
    AllowOverride none允许覆盖
    Require all granted 设置访问目录权限

    <VirtualHost 192.168.10.129:80> //绑定ip及端口
    DocumentRoot /www/129 //网站根目录
    ServerName 192.168.10.129 //网站访问的ip或域名

    4 systemctl stop fire //关闭防火墙
    5 setenforce 0 //关闭SELinux
    6 systemctl restart httpd.service //重启httpd服务
    在这里插入图片描述

1 mkdir /{xiaopang,dapang} //创建网站根目录
2 echo this is xiaopang > /xiaopang/index.html //给xiaopang的根目录写默认的html网页
3 echo this is dapang > /dapang/index.html //给dapang的根目录写默认网页
4 vim /etc/httpd/conf.d/vhosts.conf //对网页配置文件进行修改,添加模块
#允许覆盖
AllowOverride none
#设置访问目录权限
Require all granted

<VirtualHost 192.168.10.129:80>
DocumentRoot /xiaopang // 网站根目录
ServerName www.xiaopang.com //域名

<Directory /dapang>
#允许覆盖
AllowOverride none
#设置访问目录权限
Require all granted

<VirtualHost 192.168.10.140:80>
DocumentRoot /dapang //网站根目录
ServerName www.dapang.com //域名

5 systemctl restart httpd //重启httpd服务
6 vim /etc/hosts //(因为物理机win10百度后找不到hosts配置文件,故用linux自带浏览器) 添加www.xiaopang.com和www.dapang.com的dns映射

192.168.10.129 www.xiaopang.com ip到域名的映射
192.168.10.140 www.dapang.com
在这里插入图片描述
在这里插入图片描述
3.
1 mkdir /usr/local/hehe //创建虚拟目录的真实物理地址
2 echo this path is /usr/local/hehe/index.html > /usr/local/hehe/index.html //为虚拟目录写一个默认的网页
3 vim /etc/httpd/conf.d/vhosts.conf //修改配置文件
<Directory /usr/local/hehe> //开放虚拟目录所对应的真实目录的权限
#允许覆盖
AllowOverride none
#设置访问目录权限
Require all granted

<VirtualHost 192.168.10.200:80 >
DocumentRoot /www/haha
ServerName www.haha.com
alias /hehe /usr/local/hehe //给真实的目录起别名,虚拟一个目录/hehe

4  systemctl restart httpd      //重启服务

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39396529/article/details/84397225
今日推荐