1. http协议
超文本传输协议(hypertext transfer protocol),html(hyper text mark language)
http一次事务的完整过程
client --请求报文--> server
client <--响应报文-- server
Web资源
- 静态资源:png,html
- 动态资源:jsp.php
资源的定位
URL:http://172.25.254.88:80/phpadmin
2. httpd的简单应用
安装与启动
yum install httpd -y
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
主配置文件/etc/httpd/conf/httpd.conf
- 修改httpd服务默认端口
42 Listen 8080
- 修改默认发布目录(注意selinux)
119 DocumentRoot"/westos/www/html"
124 <Directory"/westos/www">
125 AllowOverride None
126 Allow open access:
127 Require all granted
128 </Directory>
163 <IfModule dir_module>
164 DirectoryIndex index.htmlwestos.html
165 </IfModule>
- httpd帮助手册
yum install httpd-manual.noarch-y
访问:http://localhost/manual
###- 虚拟主机的建立
一台服务器,baidu.com,qq.com
1). httpd的端口改为80,默认发布目录改回去;
2). 创建不同域名访问不同信息的目录
mkdir/virtual/{qq.com,baidu.com}/html -p
echo "baidu‘page">/virtual/baidu.com/html/index.html
echo "qq‘page">/virtual/qq.com/html/index.html
3). 修改配置文件/etc/httpd/conf.d/目录下
cd /etc/httpd/conf.d/
vim virtual.conf
1 <virtualhost*:80>
2 servername www.qq.com
3 serveralias qq.com
4 documentroot /virtual/qq.com/html
5 customlog "logs/qq.com.log"combined
6 </virtualhost>
7
8 <directory/virtual/qq.com >
9 require all granted
10 </directory>
vim default.conf
1 <virtualhost*:80>
2 documentroot /var/www/html
3 customlog "logs/default.log"combined
4 </virtualhost>
5 <directory/var/www>
6 require all granted
7 </directory>
systemctl start httpd
4). 修改/virtual/目录的selinux标签,selinux=enforcing
semanage fcontext -a -thttpd_sys_content_t ‘/virtual(/.*)?‘
restorecon -FvvR/virtual/
5). 客户端一定要写解析/etc/hosts
172.25.xx.xx www.baidu.com www.qq.com www.sina.com
###- 基于用户身份验证
1). 新建用户认证可以访问的网页
mkdir/var/www/html/admin
echo "admin‘spage" >/var/www/html/admin/index.html
2). 生成用户名和密码对应的文件
htpasswd -cm/etc/httpd/.htpasswd admin
htpasswd -m/etc/httpd/.htpasswd harry
3). 修改配置文件File: /home/kiosk/Desktop/http.md
vim/etc/httpd/conf.d/default.conf
<virtualhost*:80>
documentroot/var/www/html
customlog "logs/default.log"combined
</virtualhost>
<directory/var/www/html/admin>
AuthName "pleaseinput your name and passwd:"
AuthType basic
AuthUserFile /etc/httpd/.htpasswd
Require useradmin
</directory>
4). 客户端访问:http://localhost/admin
###- 自定义签名证书
* http:80 https:443
1). 安装crypto-utils软件包
yum install crypto-utilsmod_ssl -y
2). 调用genkey,生成自签名证书和私钥
genkey 172.25.254.139
3). 编辑文件/etc/httpd/conf.d/ssl.conf
SSLEngine on
SSLCertificateFile/etc/pki/tls/certs/172.25.254.139.crt
SSLCertificateKeyFile/etc/pki/tls/private/172.25.254.139.key
重启httpd服务,访问https://www.baidu.com会访问到默认访问页面
4). 编辑文件/etc/httpd/conf.d/virtual.conf
1 <virtualhost*:443>
2 servernamewww.qq.com
3 serveraliasqq.com
4 documentroot /virtual/qq.com/html
5 customlog"logs/qq.com.log" combined
6 SSLEngine on
7 SSLCertificateFile/etc/pki/tls/certs/172.25.254.139.crt
8SSLCertificateKeyFile /etc/pki/tls/private/172.25.254.139.key
9 </virtualhost>
10
11 <directory/virtual/qq.com >
12require allgranted
13 </directory>
重启httpd服务,访问https://www.qq.com会访问到/virtual/qq.com/html/index.html页面
** 注意: 1.第一次访问https://www.baidu.com (或者其他)时需要信任自签名证书;
2.下次就不需要,如果想再次信任,可以在浏览器里面设置;
###- 网页重定向(rewrite):把所有80端口的请求全部重定向由https来处理
1). 编辑/etc/httpd/conf/virtual.conf
28 <Virtualhost*:80>
29 ServerNamewww.qq.com
30 RewriteEngineon
31 RewriteRule^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
32 </Virtualhost>
2). 重启httpd服务,客户端访问www.qq.com时自动跳转到https://www.qq.com