web服务器之——基于虚拟目录和用户控制的web网站

目录

一、虚拟目录

虚拟目录的作用:

二、搭建基于虚拟目录的web网站           

1、www服务器配置

2、搭建静态网站

设置防火墙状态

关闭文件访问权限——SeLinux

3、编辑网页资源文件

4、设置虚拟目录

5、向虚拟目录中写入资源

6、重启httpd

三、搭建基于用户控制的web网站 

 1、www服务器配置

2、搭建静态网站

设置防火墙状态

关闭文件访问权限——SeLinux

3、编辑网页资源文件

4、创建管理用户

5、重启httpd

6、查看

用户访问自己主界面

三、搭建基于主机访问控制的web网站 

 1、www服务器配置

2、搭建静态网站

设置防火墙状态

关闭文件访问权限——SeLinux

3、编辑网页资源文件

4、重启httpd

5、测试

域名访问控制


一、虚拟目录

虚拟目录的作用:

        为了便于对网站资源进行灵活管理,还可以把这些文件存放在本地计算机的其它文件夹中或者其它计算机的共享文件夹中,然后再把这个文件夹映射到网站主目录中的一个文件夹上,这个文件夹被称为“虚拟目录”。

        每个虚拟目录都有一个别名,这样用户就可以通过这个虚拟目录的别名来访问与之对应的真实文件夹中的资源了。虚拟目录的好处是在不需要改变别名的情况下,可以随时改变其对应的文件夹。

二、搭建基于虚拟目录的web网站           

1、www服务器配置

web服务器之——www服务器的基本配置-CSDN博客

2、搭建静态网站

设置防火墙状态

[root@localhost html]# systemctl stop firewalld
注:临时生效命令

 默认防火墙建立22端口连接

关闭文件访问权限——SeLinux

[root@localhost html]# setenforce 0
注:临时生效命令

3、编辑网页资源文件

[root@localhost ~]# vim /etc/httpd/conf.d/virtual.conf
<VirtualHost 192.168.17.171:80>
        ServerName 192.168.17.171
        DocumentRoot /www/ip
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>

  
[root@localhost ~]# mkdir /www/ip/
[root@localhost ~]# echo thist is true > /www/ip/index.html
[root@localhost ~]# systemctl restart httpd

4、设置虚拟目录

[root@localhost ~]# vim /etc/httpd/conf.d/virtual.conf
<VirtualHost 192.168.17.171:80>
        ServerName 192.168.17.171
        DocumentRoot /www/ip
        #子界面/virtual/index.html
        Alias /1  /virtual
        #  /www/ip/1 ---> /virtual
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
​
<Directory /virtual>
        AllowOverride none
        Require all granted
</Directory>

5、向虚拟目录中写入资源

[root@localhost ~]# mkdir /virtual
[root@localhost ~]# echo this is virtual > /virtual/index.html

6、重启httpd

[root@localhost ~]# systemctl restart httpd

查看:

三、搭建基于用户控制的web网站 

 1、www服务器配置

web服务器之——www服务器的基本配置-CSDN博客

2、搭建静态网站

设置防火墙状态

[root@localhost html]# systemctl stop firewalld
注:临时生效命令

 默认防火墙建立22端口连接

关闭文件访问权限——SeLinux

[root@localhost html]# setenforce 0
注:临时生效命令

3、编辑网页资源文件

[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
<VirtualHost 192.168.17.171:80>
        ServerName 192.168.17.171
        DocumentRoot /www/ip
        #子界面/virtual/index.html
        Alias /1  /virtual
        #  /www/ip/1 ---> /virtual
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
​
<Directory /virtual>
        AllowOverride none 
        AuthType Basic   #认证类型 —— 基本认证
        AuthName "please login ......"   # 认证民称——提示信息
        AuthUserfile /etc/httpd/users   #用户认证文件
        Require user tom
</Directory>
AuthType Basic 基本认证类型(账号)
AuthName “Please login:” 提示信息,双引号必须有,可以更换为其它提示信息
AuthUserFile /etc/httpd/mymima 用户认证文件的用户名和密码指定的文件所在位置
Require user xiaoming xiaohong 指定这两个用户可以访问该服务器

4、创建管理用户

[root@localhost ~]# htpasswd -c /etc/httpd/users tom(-c表示创建)
输入密码

再次添加不需要-c

[root@localhost ~]# htpasswd /etc/httpd/users zhangsan
输入密码

添加成功:

5、重启httpd

[root@localhost ~]# systemctl restart httpd

6、查看

在浏览器中输入:http://192.168.17.171/1

【登录成功后实际上访问的是/etc/httpd/users/index.html的内容】

用户访问自己主界面

<IfModule mod_userdir.c>
• UserDir public_html 开启用户主目录
</IfModule>
<Directory /home/zhangsan/public_html>
• Authtype Basic
• AuthName "......"
• AuthUserFile /etc/httpd/userfile
• Require user zhangsan
</Directory>
#htpasswd -c /etc/httpd/userfile zhangsan
#useradd zhangsan (必须创建用户身份)
#mkdir /home/zhangsan/public_html
#chmod o+rx /home/zhangsan
#echo this is zhangsan > /home/zhangan/public_html/index.html
#systemctl restart httpd
测试:
http://www.ha1.com/~zhangsan/

三、搭建基于主机访问控制的web网站 

 1、www服务器配置

web服务器之——www服务器的基本配置-CSDN博客

2、搭建静态网站

设置防火墙状态

[root@localhost html]# systemctl stop firewalld
注:临时生效命令

 默认防火墙建立22端口连接

关闭文件访问权限——SeLinux

[root@localhost html]# setenforce 0
注:临时生效命令

3、编辑网页资源文件

[root@localhost ~]#vim /etc/httpd/conf.d/serverdir.conf
<VirtualHost 192.168.17.171:80>
        ServerName 192.168.17.171
        DocumentRoot /www/ip
        #子界面/virtual/index.html
        Alias /1  /virtual
        #  /www/ip/1 ---> /virtual
</VirtualHost>
<Directory /www>
        AllowOverride none
        <Requireall>
                Require all granted
                Require not ip 192.168.17.171  #禁止192.168.17.171访问服务器
        </Requireall>
</Directory>

4、重启httpd

[root@localhost ~]# systemctl restart httpd

5、测试

[root@localhost ~]# curl 192.168.17.171

此时出现的是Redhat访问官网欢迎界面

而客户端此时可以访问:

域名访问控制

只需将其中IP改为host即可,其余规则相同

<VirtualHost 192.168.17.171:80>
        ServerName 192.168.17.171
        DocumentRoot /www/ip
        #子界面/virtual/index.html
        Alias /1  /virtual
        #  /www/ip/1 ---> /virtual
</VirtualHost>
<Directory /www>
        AllowOverride none
        <Requireall>
                Require all granted
                Require not hosts 192.168.17.171  #禁止192.168.17.171访问服务器
        </Requireall>
</Directory>

相关推荐

  1. 大量数据优化虚拟滚动web workers

    2023-12-18 09:44:05       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-18 09:44:05       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-18 09:44:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-18 09:44:05       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-18 09:44:05       20 阅读

热门阅读

  1. Tomcat部署及优化

    2023-12-18 09:44:05       31 阅读
  2. linux程序编译、安装过程和重要参数说明

    2023-12-18 09:44:05       37 阅读
  3. random模块

    2023-12-18 09:44:05       41 阅读
  4. 【无标题】

    2023-12-18 09:44:05       34 阅读
  5. 遍历数组和里面的对象

    2023-12-18 09:44:05       42 阅读
  6. POJ 1769 Minimizing maximizer 动态规划 + 线段树

    2023-12-18 09:44:05       39 阅读
  7. 鸿蒙开发之用户隐私权限申请

    2023-12-18 09:44:05       37 阅读
  8. AcWing802. 区间和思路

    2023-12-18 09:44:05       41 阅读