本章概要
跨网络的主机间通讯
Socket套接字
客户/服务器程序的套接字函数
系统调用
HTTP服务通信过程
HTTP相关术语
html语言 #title是指表头,即网页会话框的标题
#调用马哥网站logo(属于盗链行为)
你好
#h1是指一级标题
马哥教育欢迎你
#"马哥教育"四个字为超链接
HTTP协议介绍
HTTP工作机制
HTTP连接请求
串行和并行连接
串行、持久连接和管道
URI
URL组成
http://www.magedu.com:8080/images/logo.jpg
ftp://mage:[email protected]/pub/linux.ppt
rtsp://videoserver/video_demo/
Real Time Streaming Protocol
http://www.magedu.com/bbs/hello;gender=f/send;type=title
https://list.jd.com/list.html?cat=670,671,672&ev=149_2992&sort=sort_totalsales15_desc&trans=1
http://apache.org/index.html#projects-list
网站访问量
示例:
甲乙丙三人在同一台通过ADSL上网的电脑上(中间没有断网),分别访问www.magedu.com网站,并且每人各浏览了2个页面,那么网站的流量统计是:
IP:1 PV:6 UV:1
若三人都是ADSL重新拨号后,各浏览了2个页面,则
IP:3 PV:6 UV:1
Web服务请求处理步骤
一次完整的http请求处理过程
HTTP服务器应用
MPM工作模式
prefork MPM
worker MPM
event MPM
进程角色
httpd功能特性
httpd安装
知识延伸:
检查时会出现以下提示信息:
[root@centos7 conf]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::ebd4:a16:9cb3:31f1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
如何去掉AH00558提示:需要在配置文件中设置网站名称
vim /etc/httpd/conf/httpd.conf
ServerName www.magedu.com:80 只在本地设置网站名称,别人无法通过在名称访问本主机,要想访问,需要配置dns,把想要访问该网站的dns指向该地址即可
CentOS 6 httpd程序环境
Httpd 2.2常见配置
隐藏httpd服务版本
vim /etc/httpd/conf.d/test.conf 子配置文件
ServerTokens Prod
重启服务
systemctl restart httpd
查看浏览详细信息
curl -I www.magedu.com
grep -v "^[ ]*#" /etc/httpd/conf/httpd.conf 过滤掉注释信息
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256 #最多进程数,最大20000
MaxClients 256 #最大并发
MaxRequestsPerChild 4000 #子进程最多能处理的请求数量。
#在处理MaxRequestsPerChild个请求之后,子进程将会被父进程终止,这时候子进程占用的内存就会释放(为0时永远不释放)
worker的默认配置:
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0 #无限制
注意:该模式最多默认存在4个子进程100个线程,但最大空闲线程为75,因此该模式下,刚启动为4个子进程,但等待一段时间后,会自动杀掉一个子进程,变为3个子进程
知识扩展:
系统默认为prefork模式
更改模式:更改/etc/sysconfig/httpd文件
vim /etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker 取消该行前的注释符号
重启服务
service httpd restart
LoadModuleauth_basic_module modules/mod_auth_basic.so
DocumentRoot"/app/data"
即http://HOST:PORT/test/index.html --> /app/data/test/index.html
注意:SELinux和iptables的状态
注意:
网页文件名称index.html为默认显示的网页文件,访问网页时默认省略不写,如果网页文件为其他名称如:test.html,m.html,必须指定文件名称才能显示
如:http://192.168.32.130 实际上为http://192.168.32.130/index.html,index.html默认省略不写
但如果网页文件为test.html,访问时必须写为http://192.168.32.130/test.html才能访问
...
#单个文件控制
...
#使用正则表达式控制
...
URL路径:
...
...
示例1:
#使用通配符匹配
示例2:
网站主目录/data/website/下有/admin和/blog两个目录,如果只允许130主机访问/blog目录,而不允许访问/admin目录
Require all denied
Require ip 192.168.32.130 #只允许130主机访问/admin目录
注意:以上为http2.4版本的用法
权限控制
注意:要注意RequireAll和RequireAny的区别
不能有失败,至少有一个成功匹配才成功,即失败优先
Require all granted
Require not ip 172.16.1.1 拒绝特定IP
多个语句有一个成功,则成功,即成功优先
Require all denied
require ip 172.16.1.1 允许特定IP
Options Indexes FollowSymLinks
Options FollowSymLinks
Options Indexes FollowSymLinks
Options +Includes -Indexes
(2) AllowOverride
与访问控制相关的哪些指令可以放在指定目录下的.htaccess(由AccessFileName指定)文件中,覆盖之前的配置指令
只对
AllowOverrideAll: .htaccess中所有指令都有效
AllowOverrideNone: .htaccess文件无效
AllowOverrideAuthConfigIndexes 除了AuthConfig和Indexes的其它指令都无法覆盖
(3) order和allow、deny
放在directory, .htaccess中
order:定义生效次序;写在后面的表示默认法则
Order allow,deny
Order deny,allow
Allow from和Deny from:定义客户端地址
客户端地址:
IP
网络:172.16
172.16.0.0
172.16.0.0/16
172.16.0.0/255.255.0.0
示例:
order deny,allow
deny from 172.16. 100.100
allow from 172.16
order allow,deny
deny from 172.16.100.100
allow from 172.16
为了方便对日志进行过滤,更改日志时间格式为易读格式
%t 服务器收到请求的时间
更改时间格式 %{%Y-%m-%d %H:%M:%S}t
修改日志格式:
LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog #自定义日志格式
CustomLog "logs/access_log" testlog #调用testlog日志格式在logs/access_log中写日志
Options None
AllowOverride None
AuthType Basic 验证方式
AuthName "String" 验证时弹出对话框中的提示信息
AuthUserFile"/PATH/HTTPD_USER_PASSWD_FILE" 保存验证用户名密码文件的路径
Require user username1 username2 ... 允许访问的用户
允许账号文件中的所有用户登录访问:
Require valid-user
(2) 提供账号和密码存储(文本文件)
使用专用命令完成此类文件的创建及用户管理
htpasswd [options] /PATH/HTTPD_PASSWD_FILE username
-c 自动创建文件,仅应该在文件不存在时使用
-p 明文密码
-d CRYPT格式加密,默认
-m md5格式加密
-s sha格式加密
-D 删除指定用户
实验:实现身份验证(关闭selinux和防火墙)
注意:实现验证不用添加授权,即Require all granted
vim /etc/httpd/conf.d/test.conf
AuthType Basic
AuthName "非请勿扰"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
Require user valid-user
创建保存用户名密码的文件,使用专门的创建命令htpasswd
注意:使用htpasswd命令第一次创建文件时,需要加上-c选项,第二次往后创建时要去掉-c选项,否则前面创建的文件会被覆盖
-D 删除用户密码
示例:
[root@centos7 website]# htpasswd -c /etc/httpd/conf.d/.htpasswd alice #第一次创建密码文件必须使用-c选项
New password:
Re-type new password:
Adding password for user alice
[root@centos7 website]# htpasswd /etc/httpd/conf.d/.htpasswd bob #第二次创建密码文件必须去掉-c选项,否则第一次创建的文件会被覆盖
New password:
Re-type new password:
Adding password for user bob
[root@centos7 website]# htpasswd /etc/httpd/conf.d/.htpasswd jack
New password:
Re-type new password:
Adding password for user jack
[root@centos7 website]# cat /etc/httpd/conf.d/.htpasswd
alice:$apr1$1vhxbBw.$EVmqE/y2xCNHgnzyeZMPO1
bob:$apr1$.YUPA.Q/$WgUiBVOy7FBYJWekpLsKe1
jack:$apr1$uTnnyKpI$RILMN93cBrD2dbyLKlfJs/
基于组账号进行认证
(1) 定义安全域
AuthTypeBasic
AuthName"String"
AuthUserFile"/PATH/HTTPD_USER_PASSWD_FILE"
AuthGroupFile"/PATH/HTTPD_GROUP_FILE"
Require group grpname1 grpname2 ...
(2) 创建用户账号和组账号文件
组文件:每一行定义一个组
GRP_NAME: username1 username2 …
示例:
Options None
AllowOverride None
AuthType Basic
AuthName "Administatorprivate"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
AuthGroupFile "/etc/httpd/conf.d/.htgroup"
Require group webadmins
vim /etc/httpd/conf.d/.htgroup
webadmins:wangmage
远程客户端和用户验证的控制
Satisfy ALL|Any
ALL 客户机IP和用户验证都需要通过才可以
Any客户机IP和用户验证,有一个满足即可
示例:
Require valid-user
Order allow,deny
Allow from 192.168.1
Satisfy Any
阶段小结:
[root@centos7 admin]# vim /etc/httpd/conf.d/test.conf
#网页返回索引,访问软连接
options indexes FollowSymLinks
#更改访问日志时间显示格式
LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog
CustomLog "logs/access_log" testlog #调用日志格式写入日志文件
#定义路径别名,访问非网站目录的其他目录
alias /test /app/testdir
Require all granted
#用户ip地址限制
Require all denied
Require ip 192.168.32.129
#通过URL,ip地址限制用户登录
Require all denied
Require ip 192.168.32.128
#添加网站身份验证
AuthType Basic
AuthName "secure login"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
Require valid-user
#创建保存用户密码的文件
htpasswd -c /etc/httpd/conf.d/.htpasswd tom #第一次添加必须使用-c选项
htpasswd /etc/httpd/conf.d/.htpasswd jerry
#第二次往后必须去掉-c选项,否则用户名密码会被覆盖
-D 删除用户
htpasswd -D /etc/httpd/conf.d/.htpasswd tom
vim /etc/httpd/conf/httpd.conf
#UserDir disabled
UserDir public_html #指定共享目录的名称
准备目录
su –wang;mkdir~/public_html
setfacl –m u:apache:x ~wang
访问
http://localhost/~wang/index.html
示例:
创建普通用户
登录普通用户,在该用户家目录创建将要共享的目录
su - yuan
mkdir public_html
echo test homedir > public_html/index.html
vim /etc/httpd/conf/httpd.conf
#UserDir disabled
UserDir public_html #指定用户共享目录的名称,注意:该名称必须要与中的指定的文件名称一致,否则会出错
对普通用户家目录/home/*/public_html文件进行限制,该文件名必须与上面配置中指定的文件一致
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
注意:UserDir test
则
注意:此时要更改普通用户家目录下共享目录的权限
setfacl –m u:apache:x /home/yuan
public_html文件其他权限为读和写,因此只需能够进入/home/yuan目录的权限及执行权限即可
此时,其他用户也具有访问/home/yuan/public_html目录的权限,因此需要对/home/yuan/public_html目录做身份验证
vim /etc/httpd/conf.d/userdir.conf
#
# AllowOverride FileInfo AuthConfig Limit Indexes
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# Require method GET POST OPTIONS
#
#注意要把以上内容注释掉,否则会影响以下的身份验证
AuthType Basic
AuthName "test home"
AuthUserFile "/etc/httpd/conf.d/htuser"
Require user user1 user2
htpasswd -c /etc/httpd/conf.d/htuser user1 设置用户和密码
htpasswd /etc/httpd/conf.d/htuser user2
LoadModule status_module modules/mod_status.so
SetHandler server-status
Order allow,deny
Allow from 172.16
ExtendedStatus On 显示扩展信息
ServerName FQDN
DocumentRoot "/path"
建议:上述配置存放在独立的配置文件中
其它可用指令:
ServerAlias:虚拟主机的别名;可多次使用
ErrorLog:错误日志
CustomLog:访问日志
Alias
示例1:基于IP的虚拟主机
此方法servername(域名)不起作用
增加ip地址
ip address add 192.168.32.151 dev eth0
ip address add 192.168.32.152 dev eth0
ip address add 192.168.32.153 dev eth0
ServerName www.a.com
DocumentRoot "/data/www1"
Require all granted
ServerName www.a.com
DocumentRoot "/data/www2"
Require all granted
ServerName www.a.com
DocumentRoot "/data/www3"
Require all granted
分别访问http://192.168.32.151
http://192.168.32.152
http://192.168.32.153
示例2:基于端口的虚拟主机:可和基于IP的虚拟主机混和使用
此方法servername(域名)不起作用
mkdir /data/www{1,2,3}
echo /data/www1/ > www1/index.html
echo /data/www2/ > www2/index.html
echo /data/www3/ > www3/index.html
[root@centos7 ~]#vim/etc/httpd/conf.d/virhost.conf
Listen 801
Listen 802
Listen 803
ServerName www.a.com
DocumentRoot "/data/www1"
Require all granted
ServerName www.a.com
DocumentRoot "/data/www2"
Require all granted
ServerName www.a.com
DocumentRoot "/data/www3"
Require all granted
分别访问:http://192.168.32.130:801
http://192.168.32.130:802
http://192.168.32.130:803
示例3:基于FQDN的虚拟主机
报文头部:请求报文中的一个字段
此方法通过识别报文头部中的主机名来判断与哪个虚拟主机通信
注意:在客户端配置dns解析
vim /etc/hosts
192.168.32.130 www.a.com www.b.com www.c.com
永久生效:
vim /etc/sysconfig/network-script/ifcfg-ens33
DNS1=192.168.32.130
重启网络服务
[root@centos7 ]# vim /etc/httpd/conf.d/virhost.conf
ServerName www.a.com
DocumentRoot "/data/www1"
Require all granted
CustomLog "/data/logs/a_access_log" combined
ErrorLog "/data/logs/a_error_log"
ServerName www.b.com
DocumentRoot "/data/www2"
Require all granted
CustomLog "/data/logs/b_access_log" combined
ErrorLog "/data/logs/b_error_log"
ServerName www.c.com
DocumentRoot "/data/www3"
Require all granted
CustomLog "/data/logs/c_access_log" combined
ErrorLog "/data/logs/c_error_log"
mkdir /data/logs
重启服务,即会自动生成日志文件
知识扩展:
一个虚拟主机有多个域名,如何实现
通过域名别名实现
ServerAlias a.com \*.a.com
ServerName www.a.com
DocumentRoot "/data/www1"
Require all granted
CustomLog "/data/logs/a_access_log" combind
ErrorLog "/data/logs/a_error_log"
ServerAlias a.com *.a.com
要注意域名解析配置
vim /etc/hosts
192.168.32.130 a.com b.a.com zzz.a.com
httpd-2.4
CentOS 7 httpd程序环境
httpd-2.4配置
ServerName www.b.net
DocumentRoot "/apps/b.net/htdocs"
Options None
AllowOverride None
Require all granted
注意:任意目录下的页面只有显式授权才能被访问
(5) KeepAlive on
KeepAliveTimeout #ms
MaxKeepAliveRequests 100
毫秒级持久连接时长定义
mod_deflate模块
https
https实现
实验:实现https
https工作过程(该过程包含三个身份:客户端、服务器端、CA)
1、客户端client向服务端server发出请求,要登录https://www.domain.com
2、服务端把已经拥有的证书发送给客户端,该证书内容包括服务端自己的公钥、ca的私钥签名、网站信息、证书有效期;而且该证书已经用数字签名(即使用CA的私钥加密)保证其来源的可靠性
3、客户端信任CA,使用已经获取的CA的公钥进行解密,获取证书中服务端的公钥,此公钥确定是可靠可信的
4、客户端生成随机字符串session key(即会话密钥,也叫对称密钥),使用服务端的公钥加密随机字符串key,传递给服务端
5、服务器使用自己的私钥解密公钥加密的数据,获取key
6、随后,通讯双方即可使用key加密数据进行通讯
实现https
不支持基于FQDN的多虚拟主机https加密,只支持一个ip地址
服务器端:192.168.32.129
客户端:192.168.32.130
客户端配置:
使用/var/www/html作为网页主目录
mv virhost.conf virhost.conf.bak 不再使用virhost.conf作为配置文件
网站主页写入测试数据
echo /var/www/html/index.html > /var/www/html/index.html
#安装ssl模块
yum -y install mod_ssl
#创建存放证书目录
mkdir /etc/httpd/conf.d/ssl
cd /etc/httpd/conf.d/ssl
#创建客户端私钥
[root@centos7 ssl]# (umask 066;openssl genrsa -out http.key 1024)
#生成证书申请
[root@centos7 ssl]# openssl req -new -key http.key -out http.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN #国家
State or Province Name (full name) []:beijing #省份
Locality Name (eg, city) [Default City]:beijing #城市
Organization Name (eg, company) [Default Company Ltd]:magedu #公司
Organizational Unit Name (eg, section) []:opt #部门
Common Name (eg, your name or your server's hostname) []:www.a.com #公司域名
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
scp http.csr 192.168.32.129:/etc/pki/CA
服务器端配置:
cd /etc/pki/CA
#以下两项必须创建,否则颁发证书会出错
touch index.txt
echo 01 >serial
#创建服务器端私钥
(umask 077;openssl genrsa -out private/cakey.pem 2048)
#创建自签名证书
[root@centos7-1 CA]#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:magedu
Organizational Unit Name (eg, section) []:opt
Common Name (eg, your name or your server's hostname) []:ca.magedu.com
Email Address []:
#颁发CA证书
[root@centos7-1 CA]#openssl ca -in http.csr -out http.crt -days 3650
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Oct 19 09:22:35 2018 GMT
Not After : Oct 16 09:22:35 2028 GMT
Subject:
countryName = CN
stateOrProvinceName = beijing
organizationName = magedu
organizationalUnitName = opt
commonName = ca.magedu.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
57:84:A7:62:51:BF:55:35:B1:42:E3:EB:67:99:46:83:2C:BF:A2:2F
X509v3 Authority Key Identifier:
keyid:A6:F4:6B:28:D5:A6:E5:C1:A3:38:12:CA:2B:7D:3F:1C:E2:F3:CC:6A
Certificate is to be certified until Oct 16 09:22:35 2028 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@centos7-1 CA]#tree
.
├── cacert.pem
├── certs
├── crl
├── http.crt
├── http.csr
├── index.txt
├── index.txt.attr
├── index.txt.old
├── newcerts
│ └── 01.pem
├── private
│ └── cakey.pem
├── serial
└── serial.old
4 directories, 11 files
#把证书传给客户端
scp http.crt cacert.pem 192.168.32.130:/etc/httpd/conf.d/ssl
客户端配置:
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/conf.d/ssl/http.crt #客户端证书路径
SSLCertificateKeyFile /etc/httpd/conf.d/ssl/http.key #客户端私钥路径
SSLCACertificateFile /etc/httpd/conf.d/ssl/cacert.pem #服务器端自签名证书存放路径
重启服务
systemctl restart httpd
验证:在其他主机执行以下命令
openssl s_client -connect 192.168.32.130:443 -CAfile cacert.pem
或curl --cacert cacert.pem https://www.a.com
注意:配置https加密要对网站主目录文件进行授权(centos7系统http2.4版本默认要对主目录文件进行授权)即:
ServerName www.wordpress.net
DocumentRoot /data/wordpress
Require all granted 对主目录进行授权
http重定向https
Redirect Permanent / https://192.168.32.130
如果从非加密网站重定向加密网站,此写法会造成无限跳转,造成死循环
解决方法:
在 <\VirtualHost \*:80><\VirtualHost> 标签内随便一个地方加入以下三行
或者单独编辑在一个文件中
vim /etc/httpd/conf.d/test2.conf
#Redirect Permanent / https://192.168.32.130 注释掉该行
RewriteEngine on
Rewritecond %{SERVER_PORT} !^443
RewriteRule ^(/.\*)$ https://%{HTTP_HOST}$1 [redirect=302] 临时重定向
注意:正常情况下,加密和非加密主页应存放在同一个目录,该配置是为了做实验才这样写
HSTS
vim /etc/httpd/conf/httpd.conf
Header always set Strict-Transport-Security "max-age=31536000"
RewriteEngineon
RewriteRule^(/.\*)$ https://%{HTTP_HOST}$1 [redirect=302]
知识扩展:
服务器端配置支持HSTS后,会在给浏览器返回的HTTP首部中携带HSTS字段。浏览器获取到该信息后,会将所有HTTP访问请求在内部做307跳转到HTTPS,在下次访问该网站时会直接使用https加密方式连接,而无需任何网络过程
如果不做跳转,那么每次浏览器访问服务器,第一次连接时,都是以http连接,这样是及其不安全的
HSTS有时间期限
但是在第一次访问网站时,仍然是http协议连接,仍然是不安全的
HSTS preload list HSTS预载入列表
该列表载入了世界上支持https的网站,只要在该列表中进行浏览器注册,通过该浏览器第一次访问该HSTS载入列表中存在的网站时,会自动以https加密连接,
反向代理功能
ServerName www.magedu.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Sendfile机制
http协议
http协议
http/0.9, http/1.0, http/1.1, http/2.0
http协议:stateless 无状态
服务器无法持续追踪访问者来源
解决http协议无状态方法
cookie 客户端存放
session 服务端存放
http事务:一次访问的过程
请求:request
响应:response
HTTP请求报文
HTTP响应报文
报文语法格式:
request报文
response报文
method: 请求方法,标明客户端希望服务器对资源执行的动作
GET、HEAD、POST等
version:
HTTP/.
status:
三位数字,如200,301, 302, 404, 502; 标记请求处理过程中发生的情况
reason-phrase:
状态码所标记的状态的简要描述
headers:
每个请求或响应报文可包含任意个首部;每个首部都有首部名称,后面跟一个冒号,而后跟一个可选空格,接着是一个值
entity-body:请求时附加的数据或响应时附加的数据
Method 方法:
GET:从服务器获取一个资源
HEAD:只从服务器获取文档的响应首部
POST:向服务器输入数据,通常会再由网关程序继续处理
PUT:将请求的主体部分存储在服务器中,如上传文件
DELETE:请求删除服务器上指定的文档
TRACE:追踪请求到达服务器中间经过的代理服务器
OPTIONS:请求服务器返回对指定资源支持使用的请求方法
协议查看或分析的工具:
tcpdump, wireshark,tshark
http协议状态码分类
504状态码
404状态码
status(状态码):
1xx:100-101信息提示
2xx:200-206成功
3xx:300-305重定向
4xx:400-415错误类信息,客户端错误
5xx:500-505错误类信息,服务器端错误
http协议常用的状态码
200:成功,请求数据通过响应报文的entity-body部分发送;OK
301:请求的URL指向的资源已经被删除;但在响应报文中通过首部Location指明了资源现在所处的新位置;Moved Permanently
302:响应报文Location指明资源临时新位置Moved Temporarily
304:客户端发出了条件式请求,但服务器上的资源未曾发生改变,则通过响应此响应状态码通知客户端;Not Modified
401:需要输入账号和密码认证方能访问资源;Unauthorized
403:请求被禁止;Forbidden
404:服务器无法找到客户端请求的资源;Not Found
500:服务器内部错误;Internal Server Error
502:代理服务器从后端服务器收到了一条伪响应,如无法连接到网关;Bad Gateway
503:服务不可用,临时服务器维护或过载,服务器无法处理请求
504:网关超时
http首部字段
http协议首部
Cookie
Set-Cookie首部字段
Set-Cookie: status=enable; expires=Fri, 24 Nov 2017 20:30:02 GMT; path=/;
NAME=VALUE 赋予Cookie 的名称和其值,此为必需项
expires=DATE Cookie的有效期,若不明确指定则默认为浏览器关闭前为止
path=PATH 将服务器上的文件目录作为Cookie的适用对象,若不指定则默认为文档所在的文件目录
domain=域名 作为Cookie 适用对象的域名,若不指定则默认为创建Cookie的服务器的域名
Secure 仅在HTTPS安全通信时才会发送Cookie
HttpOnly 加以限制使Cookie不能被JavaScript脚本访问
curl工具
-A/--user-agent 设置用户代理发送给服务器
-e/--referer 来源网址
--cacert CA证书(SSL)
-k/--insecure 允许忽略证书进行SSL连接
--compressed 要求返回是压缩的格式
-H/--header 自定义首部信息传递给服务器
-i 显示页面内容,包括报文首部信息
-I/--head 只显示响应报文首部信息
-D/--dump-header 将url的header信息存放在指定文件中
--basic 使用HTTP基本认证
-u/--user 设置服务器的用户和密码
-L 如果有3xx响应码,重新发请求到新位置
-O 使用URL中默认的文件名保存文件到本地
-o 将网络文件保存为指定的文件中
--limit-rate 设置传输速度
-0/--http1.0 数字0,使用HTTP 1.0
-v/--verbose 更详细
-C 选项可对文件使用断点续传功能
-c/--cookie-jar 将url中cookie存放在指定文件中
-x/--proxy 指定代理服务器地址
-X/--request 向服务器发送指定请求方法
-U/--proxy-user 代理服务器用户和密码
-T 选项可将指定的本地文件上传到FTP服务器上
--data/-d 方式指定使用POST方式传递数据
-b name=data 从服务器响应set-cookie得到值,返回给服务器
httpd自带的工具程序
httpd的压力测试工具
ARP
在centos6编译安装httpd-2.4
centos6编译安装httpd-2.4方法二