linux搭建静态及用户访问控制

案例1:搭建http静态页面路径为/www,域名为www.zbt.com

思路:主界面为/www/index.html

安装httpd服务

yum install httpd -y

启动httpd服务

systemctl restart httpd

创建  /etc/httpd/conf.d/vhosts.conf(自定义网站目录)

vim /etc/httpd/conf.d/vhosts.conf

    <Directory /www>
            AllowOverride none    ----允许覆盖
            Require all granted    ----设置访问目录权限
    </Directory>
    <VirtualHost (本地ip):80>
            DocumentRoot /www    ----指定当前主机访问网站根目录
            ServerName www.zbt.com    ----指定访问网站名称
            ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"        ---错误日志
            CustomLog "/var/log/httpd/dummy-host2.example.com-access_log"common    ---访问日志
    </VirtualHost>

添加网站内容

echo "网站内容" > /www/index.html

进入/etc/hosts文件

添加ip、添加域名

172.52.16.30(本地IP) www.zbt.com

访问172.52.16.30或者www.zbt.com

显示/www/index.html中内容

 

案例2:搭建http静态页面,在www下创新路径访问页面,当用户1为zbt密码root,用户2为syt密码为root,才可以进入。

思路:主界面为/www/index.html

用户访问界面设为/www/user/index.html

创建/www/index.html文件并写入"网站内容"

创建/www/user/index.html文件并写入"用户控制"

修改vhosts.conf配置文件

<Directory /www>                      ---自定义目录
        AllowOverride none
        Require all granted
</Directory>

<Directory /www/user>                
        AuthType Basic                ---基本认证类型(基于Basic认证)
        AuthName "输入用户名密码"       ---提示信息
        AuthUserFile /etc/httpd/users ---用户认证文件用户名和密码文件
        Require user zbt syt          ---指定有效用户可以进入
</Directory>
<VirtualHost 172.52.16.30:80>         ---如果访问用户控制界面,则访问www.xixi.com/user
        DocumentRoot /www
        ServerName www.xixi.com
</VirtualHost>

 加域名为:

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<Directory /www/user>
        AuthType Basic
        AuthName "输入用户名密码"
        AuthUserFile /etc/httpd/users
        Require user zbt syt
</Directory>
<VirtualHost 172.52.16.30:80>
        DocumentRoot /www
        ServerName www.xixi.com
</VirtualHost>


<VirtualHost 172.52.16.30:80>
        DocumentRoot /www/user
        ServerName www.yonghu.com
</VirtualHost>

 创建可用用户zbt,syt及不可用用户hhh

htpasswd -c /etc/httpd/users zbt
htpasswd /etc/httpd/users  syt
htpasswd /etc/httpd/users  hhh

进入域名管理文件,添加域名

vim /etc/hosts
172.52.16.30 www.xixi.com
172.52.16.30 www.yonghu.com

访问curl 172.52.16.30或www.xixi.com

显示:网站内容

访问curl 172.52.16.30/user或www.yonghu.com

显示用户名密码输入进入则为/user的index.html

 

 

 

案例3:正常访问/www主页面为"网站内容",把用户访问控制放在真实路径下/zbt/yonghu,而虚拟路径为/www/yonghu

思路:创建/www/index.html显示网站内容,创建/zbt/yonghu/index.html显示"用户控制"

添加域名

更改配置文件vhosts.conf

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<Directory /zbt/yonghu>
        AuthType Basic
        AuthName "输入用户名密码"
        AuthUserFile /etc/httpd/users
        Require user zbt syt
</Directory>
<VirtualHost 172.52.16.30:80>            --主域名
        DocumentRoot /www
        ServerName www.zbt.com
        Alias /yonghu /zbt/yonghu
</VirtualHost>
---------------------------------------------------------------
<VirtualHost 172.52.16.30:80>            --加域名
        DocumentRoot /zbt/yonghu
        ServerName www.yonghu.com
</VirtualHost>

添加域名

172.52.16.30 www.zbt.com
172.52.16.30 www.yonghu.com

 访问www.zbt.com或172.52.16.30显示网站内容

访问www.yonghu.com或者172.52.16.30/yonghu显示/zbt/yonghu/index.htnml内容

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值