企业服务(Apache服务)

Apache服务
用户访问控制,认证方式有basic和digest两种
首先创建用户认证文件,为用户认证做准备

[root@centos7-client html]# htpasswd -c  -m   /etc/httpd/conf.d/.htpassword    wangy
New password: 
Re-type new password: 
Adding password for user wangy

//有以下四种加密手段,其中MD5是最常规的 BCRYPT是强加密
-m Force MD5 encryption of the password (default).
-2 Force SHA-256 crypt() hash of the password (secure).
-5 Force SHA-512 crypt() hash of the password (secure).
-B Force bcrypt aencryption of the password (very secure).

[root@centos7-client html]# htpasswd -b  -m   /etc/httpd/conf.d/.htpassword lisi   lisi
Adding password for user lisi

// -b参数就不用去输入用户密码 可以直接放在命令行当中

接下来我们要修改配置文件,让目录添加认证参数

[root@centos7-client html]# vim  /etc/httpd/conf/httpd.conf
DocumentRoot "/webdata/www/html"
<Directory "/webdata/www/html">
    AuthType Basic
    AuthName "Restricted Resource"
    AuthBasicProvider file
    AuthUserFile /etc/httpd/conf.d/.htpassword
    Require user wangy
</Directory>
[root@centos7-client html]# mkdir  -p   /webdata/www/html
[root@centos7-client html]# echo   hello,world  >   /webdata/www/html/index.html
[root@centos7-client html]# systemctl restart httpd

最后我们进行测试,因为我们目录放行的是wangy这个用户,所以哪怕lisi这个用户已经创建了加密文件,但是依旧无法登录
在这里插入图片描述
浏览器不同,提示框也不同,输入用户名和密码进行登录,我们还可以发现 lisi是没法登录网站的

Options指令
后面跟1个或者多个以空白字符分隔的选项列表,在选项前面可以用 + ,- 表示增加或者删除指定选项
常见选项(默认是全部禁用的)
Indexes : 指明的URL 路径下不存在与定义的主页面资源相符的资源文件,返回索引列表给用户
FollowSymLinks :允许访问符号链接文件所指向的源文件
None: 全部禁用
ALL:全部允许

修改配置文件:

[root@centos7-client html]# vim  /etc/httpd/conf/httpd.conf
<Directory "/webdata/www/html">
    Options +Indexes                  //加上这个参数
    AuthType Basic
    AuthName "Restricted Resource"
    AuthBasicProvider file
    AuthUserFile /etc/httpd/conf.d/.htpassword
    Require user wangy
</Directory>

接下来我们创建一个目录,找不到主页 但是因为加上了+Indexes 所以找不到资源index.html主页,所以直接索引列表给用户,所以加上这个参数是不安全的。

[root@centos7-client html]# mkdir    source
[root@centos7-client html]# cd source/
[root@centos7-client source]# touch  file1   file2
[root@centos7-client source]# ll
total 0
-rw-r--r--. 1 root root 0 Feb 20 21:20 file1
-rw-r--r--. 1 root root 0 Feb 20 21:20 file2

首先我们创建软连接,把/etc下的配置文件 链接到/webdata/www/html/source目录当中

[root@centos7-client source]# ln  -s   /etc/hosts     hosts
[root@centos7-client source]# ll
total 0
-rw-r--r--. 1 root root  0 Feb 20 21:20 file1
-rw-r--r--. 1 root root  0 Feb 20 21:20 file2
lrwxrwxrwx. 1 root root 10 Feb 20 21:37 hosts -> /etc/hosts

此时去访问浏览器,居然发现,链接文件也可以显示,直接可以通过web来访问,这个是不安全的

所以我们要在配置文件当中,把这个功能禁用FollowSymLinks

[root@centos7-client source]# vim  /etc/httpd/conf/httpd.conf 
<Directory "/webdata/www/html">
    Options +Indexes
    Options -FollowSymLinks
    AuthType Basic
    AuthName "Restricted Resource"
    AuthBasicProvider file
    AuthUserFile /etc/httpd/conf.d/.htpassword
    Require user wangy
</Directory>
[root@centos7-client source]# systemctl restart httpd

重启服务 我们继续访问会发现,此时链接文件不见了。

虚拟主机:

  1. 基于IP地址的虚拟主机
  2. 基于端口的虚拟主机

首先我们在/webdata目录下 创建四个站点分别为site1 site2 site3 site4
我们分别给四个站点 设置index.html 设置内容为hello,this is siteX
基于ip的虚拟主机,以虚拟web主机使用不同的ip地址,通过一台httpd服务器,对外提供web功能,
所以我们的虚拟web服务器,需要有大量的网络接口,在显示中不太好实现,所以一般都是基于端口做虚拟主机。

基于端口的虚拟主机,增加一个配置文件

[root@centos7-client webdata]# vim  /etc/httpd/conf.d/site.conf 
Listen 8080
Listen 9090
<Directory "/webdata/">
    Require all granted
</Directory>
<VirtualHost *:8080>
    DocumentRoot "/webdata/site1/"
</virtualHost>

<VirtualHost *:9090>
    DocumentRoot "/webdata/site2/"
</virtualHost>
[root@centos7-client webdata]# systemctl restart httpd
[root@centos7-client webdata]# curl  192.168.40.178:8080
<h1> hello,this is site1    </h1>
[root@centos7-client webdata]# curl  192.168.40.178:9090
<h1> hello this is Site2  </h1>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值