超文本传输协议 (英语: HyperText Transfer Protocol, 缩写: HTTP) 是一种用于分布式, 协作式和超媒体信息系统的应用层协议. HTTP 是万维网的数据通信的基础.
?
(一)基于用户的访问控制
?
认证: Authorization: 客户端用户填入账号和密码后再次发送请求报文; 认证通过时, 则服务器发送响应的资源;
?
认证方式有两种:
basic: 明文
digest: 消息摘要认证
?
?
basic 认证配置示例
(1) 定义安全域
- <Directory "">
- Options None
- AllowOverride None
- AuthType Basic
- AuthName "String"
- AuthUserFile "/PATH/TO/HTTPD_USER_PASSWD_FILE"
- Require user username1 username2 ...
- </Directory>
(2) 提供账号和密码存储
使用 htpasswd 命令进行维护
htpasswd? [OPTIONS]? passwdfile? ?userName
选项有:? ? ? ? ? ?
-c: 添加第一个用户时创建此文件?
-m:md5 格式加密用户密码存放?
-s:sha 格式加密用户密码存放
-D: 删除指定用户
-b: 批模式添加用户
htpasswd -b [options] /PATH/TO/HTTPD_PASSWD_FILE username password
基于组账号进行认证
(1) 定义安全域
- <Directory "">
- Options None
- AllowOverride None
- AuthType Basic
- AuthName "String"
- AuthUserFile "/PATH/TO/HTTPD_USER_PASSWD_FILE"
- AuthGroupFile "/PATH/TO/HTTPD_GROUP_FILE"
- Require group grpname1 grpname2 ...
- </Directory>
(2) 创建用户账号和组账号文件;
组文件: 每一行定义一个组
- GRP_NAME: username1 username2
- ?
- ?
(二)虚拟主机
基于 ip: 为每个虚拟主机准备至少一个 ip 地址;
- <VirtualHost 10.120.123.6:80>
- ServerName www.a.com
- DocumentRoot "/www/a.com/htdocs"
- </VirtualHost>
- <VirtualHost 10.120.123.7:80>
- ServerName www.b.NET
- DocumentRoot "/www/b.net/htdocs"
- </VirtualHost>
基于 port: 为每个虚拟主机使用至少一个独立的 port;
- <VirtualHost 10.120.123.6:80>
- ServerName www.a.com
- DocumentRoot "/www/a.com/htdocs"
- </VirtualHost>
- <VirtualHost 10.120.123.6:8080>
- ServerName www.b.NET
- DocumentRoot "/www/b.net/htdocs"
- </VirtualHost>
基于 FQDN: 为每个虚拟主机使用至少一个 FQDN;
- <VirtualHost 10.120.123.6:80>
- ServerName www.a.com
- DocumentRoot "/www/a.com/htdocs"
- </VirtualHost>
- <VirtualHost 10.120.123.6:80>
- ServerName www.b.NET
- DocumentRoot "/www/b.net/htdocs"
- </VirtualHost>
(三)HTTPS 经由 HTTP 进行通信, 但利用 SSL/TLS 来加密数据包
?
1. 安装 mod_ssl 包, 配置 http 支持 https
- yum -y install mod_ssl
- httpd -M | grep ssl
- ssl_module (shared)
2. 建立私有 CA
(1)生成私钥
(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
(2)生成自签证书
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650
3. 在服务器端创建签署请求, CA 签证
(1)生成私钥
- mkdir /etc/httpd/ssl
- cd /etc/httpd/ssl
- (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
(2)生成签署请求
openssl req -new -key httpd.key -out httpd.csr -days 365
(3)CA 签证
openssl ca -in httpd.csr -out /etc/httpd/ssl/httpd.crt -days 365
修改配置文件: VIM /etc/httpd/conf.d/ssl.conf
- <VirtualHost 10.120.123.6:443>
- ServerName www.a.com
- DocumentRoot /www/a.com/htdocs
- SSLengine ON
- SSLprotocol ALL -sslv2 -sslv3
- SSLcertificatefile /etc/httpd/ssl/httpd.crt
- SSLcertificatekeyfile /etc/httpd/ssl/httpd.key
- </VirtualHost>
Linux 基础知识(十一)HTTPD
来源: http://www.bubuko.com/infodetail-3010041.html