HTTP

作者: Miracle001 | 来源:发表于2018-03-08 09:10 被阅读0次
    第一讲
    centos6
    cd /var/www/html
    vim index.html
    <html> 
    <head>
    <title>html语言</title> 
    </head> 
    <body> 
    <h1>标题1</h1> 
    <p><a href=http://www.magedu.com> 马哥教育 </a>欢迎你 </p> 
    <h2>标题2</h2> 
    </body> 
    </html>
    ss -ntl
    service httpd start
    ss -ntl  80端口打开
    iptables -vnL
    chkconfig iptables off
    service iptables stop
    centos7
    systemctl disable firewalld
    systemctl stop firewalld
    网页访问:192.168.29.126
    centos6
    vim index.txt
    欢迎来到lol
    网页访问:192.168.29.126/index.txt
    数据的封装:后——>前: 帧(帧:源/目标mac地址)+ip+tcp+http报头+data  
    http://www.w3school.com.cn/media/media_mimeref.asp
    此网站是在线的html教学,可以看看
    developer.mozilla.org  在线教学html
    www.jr.jd.com  右键,查看网页源代码
    mac.xunlei.com  网页很炫,看看即可
    
    第二讲
    cat /etc/mime.types
    curl -I www.jd.com  只看头部
    抓包软件:wireshark
    URL: Uniform Resorce Locator,统一资源定位符,用于描述某服务器某特定资源位置 
    <scheme>://<user>:<password>@<host>:<port>/<path>;<params> ?<query>#<frag> 
    IP(独立IP):
    记录远程客户机IP地址的计算机访问网站的次数,是衡量网站流量的重要指标。 
    浏览器:www.ip138.com  可以显示出地址来源
    centos7命令行操作:firefox www.ip138.com
    PV(访问量):网站被访问的页面数量 
    UV(独立访客):访问某网站的电脑的数量
    网站统计排名:http://www.alexa.cn/rank/
    pstree -p  查看http的进程
    centos7操作:
    yum -y install telnet
    操作1
    telnet 192.168.29.126 80
    GET / HTTP/1.1  ——> 下载 主页 http/1.1  ——> 主页就是/var/www/html
    资源放置于本地文件系统特定的路径:DocRoot DocRoot  /var/www/html  映射关系
    host: 192.168.29.126
    回车
    回车
    GET  必须大写,其他无所谓
    操作2
    centos6
    cd /var/www/html
    mkdir /var/www/html/download/
    echo "welcome to lol" > /var/www/html/download/a.txt
    cat /var/www/html/download/a.txt
    centos7
    telnet 192.168.29.126 80
    GET /download/a.txt http/1.1
    host: 192.168.29.126
    操作3
    centos6
    cd /var/www/html;ll
    ln -s  ../../../../etc/fstab  download/fstab
    ll download/fstab
    centos7
    telnet 192.168.29.126 80
    GET /download/fstab http/1.1
    host: 2.2.2.2 有时候可以与telnet的IP不一致,但是有时候是强制一致的
    centos6
    cat /var/log/httpd/access_log  记录日志
    市场占有率统计 www.netcraft.com
    http://www.apache.org/
    点击:HTTP Server
    ulimit -a  查看用户的进程最大数量
    
    第三讲
    centos6
    ll /etc/httpd/  配置文件以此文件夹为根
    chkconfig --list httpd
    chkconfig httpd on
    service httpd status
    service httpd start
    ps aux  以root身份运行,以apache身份提供服务
    cat /etc/init.d/httpd  脚本
    cat /etc/sysconfig/httpd  脚本配置文件
    检查配置语法: 
    httpd –t 
    service httpd configtest
    which httpd
    站点网页文档根目录: /var/www/html 
    模块文件路径: 
    /etc/httpd/modules  软链接 
    /usr/lib64/httpd/modules  真实路径
    主程序文件: 
    ll /usr/sbin/ht*
    帮助文档包: httpd-manual
    yum -y install httpd-manual
    rpm -ql httpd-manual
    service httpd restart
    浏览器:http://192.168.29.126/manual/
    主配置文件/etc/httpd/conf/httpd.conf  备份一下
    cd /etc/httpd/conf, ll
    cp httpd.conf httpd.conf.bak, ll
    grep -v "^#" httpd.conf|grep -v "^$"|less
    配置格式:directive value  指令 值
    解决服务器名称报错信息
    法一:
    vim httpd.conf
    搜索"/ServerName"
    #ServerName www.example.com:80  去掉"#"即可,建议写自己网站的真正的名字
    httpd -t  即可解决报错信息
    法二:
    vim /etc/hosts
    第一行localhost前面,添加centos6.fgq.com,也可以解决报错信息
    显示服务器版本信息 ServerTokens
    vim httpd.conf
    搜索:/ServerTokens
    ServerTokens OS   OS改为prod或者productonly
    service httpd reload
    浏览器:
    http://httpd.apache.org/ ——>project——>HTTP Server——>Documentation,Version 2.2——>
    配置指令——>S——>ServerTokens——>ServerTokens Directive 查看相关信息
    centos7操作:
    curl -I 192.168.29.126  Server就不会出现apache版本号了,不易受到攻击了
    yum -y install elinks
    elinks 192.168.29.126
    centos6
    vim httpd.conf
    搜索:/Listen
    Listen 80  注释掉#
    添加信息
    Listen 192.168.29.126:80或者Listen 192.168.1.5:80或者
    Listen 192.168.29.126:9527 或者 再添加一条:listen 80
    非标准端口9527,selinux需要关闭
    getenforce
    setenforce 0
    vim /etc/selinux/config
    enforcing改为permissive
    service httpd restart  需要重启服务,reload不可以
    ss -ntl
    centos7操作:curl -I 192.168.1.5访问不了
    或者
    centos7操作:curl -I 192.168.29.126访问不了
    或者
    centos7操作:curl -I 192.168.29.126:9527 看头部    curl 192.168.29.126:9527 看网页
    或者
    centos7操作:
    curl -I 192.168.29.126:9527 或 curl -I 192.168.1.5 或 
    curl -I 192.168.29.126 或 curl -I 192.168.1.5:9527访问不了
    vim httpd.conf
    搜索:/Keepalive  把off变为on
    15s断开改为20s断开
    service httpd restart
    centos7
    telnet 192.168.29.126 80
    GET / http/1.1
    host:2.2.2.2
    最下面出现:Connection closed by foreign host 表示KeepAlive是off的
    telnet 192.168.29.126 80
    GET / http/1.1
    host:2.2.2.2
    GET /a.txt http/1.1
    host:2.2.2.2
    20s后即会断开
    游戏电商需要持久连接,根据访问量控制断开时间
    更换使用的httpd程序
    vim /etc/sysconfig/httpd 
    HTTPD=/usr/sbin/httpd.worker 去掉#,使其生效
    service httpd restart
    pstree -p|grep httpd 
    centos7
    yum -y install httpd-tools
    ab -c 1000 -n 10000 http://192.168.29.126/  测试性能
    
    第四讲
    vim /etc/init.d/httpd
    编译安装此文件作为模板,更改文件的路径即可
    vim .bashrc
    增加信息:
    alias cdnet='cd /etc/sysconfig/network-scripts'
    alias vihttpd='vim /etc/httpd/conf/httpd.conf'
    alias cdwww='cd /var/www/html'
    . .bashrc
    . ~/.bashrc  使文件生效  刚打开一个新界面,别名不能用时,使用此命令
    打开新界面:. /root/.bashrc使命令生效
    vim /etc/httpd/conf/httpd.conf
    prefork的默认配置: ppt
    worker的默认配置: ppt
    cd /etc/httpd/modules
    pwd -P  看真正的物理路径
    加载动态模块配置 
    /etc/httpd/conf/httpd.conf 
    配置指定实现模块加载格式: LoadModule <mod_name>  <mod_path> 
    模块文件路径可使用相对路径: 相对于ServerRoot(默认/etc/httpd) 
    定义'Main' server的文档页面路径 
    vim /etc/httpd/conf/httpd.conf
    搜索:/DocumentRoot
    DocumentRoot "/var/www/html"改为:"/app/website1"
    cd /app;mkdir website1;cd website1;
    vim index.html
    <h1>welcome to website1</h1>
    service httpd reload
    浏览器:192.168.29.126看是否成功
    vim /etc/httpd/conf/httpd.conf
    搜索:/conf.d  
    /etc/httpd/conf.d/*.conf  这也是配置文件
    cd /etc/httpd/conf.d
    cat welcome.conf
    mv welcome.conf welcome.conf.bak  欢迎界面即可关闭
    error文件在/var/www/error,在图形界面观看,即可看到内容
    cd /var/www/html
    mv index.html a.html
    service httpd restart
    浏览器:192.168.29.126 可以访问到索引列表
    <Directory>中“基于源地址”实现访问控制 
    vim /etc/httpd/conf/httpd.conf
    Options -Indexes FollowSymLinks  Indexes前面加一个减号,不能访问索引列表
    注释掉DocumentRoot "/var/www/html"并在下面添加信息
    DocumentRoot "/app/website1"
    <Directory "/app/website1">
    Options indexes
    </Directory>
    !ser
    浏览器:192.168.29.126 可以访问到索引列表
    Options -indexes  在indexes前面加一个减号即不能访问
    cd /app/website1;
    ln -s ../../etc/hosts hosts.txt;ll
    浏览器:192.168.29.126/hosts.txt
    vim /etc/httpd/conf/httpd.conf
    Options -indexes -FollowSymLinks
    service httpd restart
    浏览器:192.168.29.126/hosts.txt  禁止访问
    indexes  不写,默认不开启
    FollowSymLinks  不写,默认开启
    cd /app/website1;mkdir bbs;
    cd bbs/;
    cp /etc/fstab a.txt
    cp /etc/fstab b.txt
    ln -s ../../../../etc/hosts hosts.txt
    浏览器:更改设置,看是否可以看到索引列表,父目录控制子目录
    vim /etc/httpd/conf/httpd.conf
    搜索:/.htaccess  
    AccessFileName .htaccess  注意准确定位
    搜索:/website1
    Options此行内容更改为:AllowOverride All
    cd /app/website1;
    vim .htaccess
    options indexes followsymLinks
    浏览器:192.168.29.126
    一般不用.htaccess,易乱
    ll -a
    order和allow、deny order:
    定义生效次序;写在后面的表示默认法则 
    Order allow,deny 
    Order deny,allow 
    vim /etc/httpd/conf/httpd.conf
    搜索:/website1
    AllowOverride All此行内容更改为:
    order allow,deny
    deny from 192.168.29.127
    allow from 192.168.29.1
    !ser
    httpd -t
    centos7:curl http://192.168.29.126/   403 Forbidden
    浏览器:192.168.29.126
    cd /app/website1
    mv a.txt indexes.html
    vim /etc/httpd/conf/httpd.conf
    allow from 192.168.29.1  把1变为127
    !ser
    浏览器:192.168.29.126
    
    
    第五讲
    cat /var/log/httpd/error_log
    vim /etc/httpd/conf/httpd.conf
    搜索:/error_log
    debug, info, notice, warn, error, crit,alert, emerg
    LogLevel warn  表示warn以上级别(严重)的操作需要记录日志
    搜索:/mod_log  
    mod_log_config  记录日志的模块,禁用则不能记录日志
    浏览器:http://httpd.apache.org/docs/2.2/logs.html  ——>format strings
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
    
    %h 客户端IP地址 
    %l  远程用户,启用mod_ident才有效,通常为减号“-” 
    %u  验证(basic,digest)远程用户,非登录访问时,为 一个减号“-”
    %t 服务器收到请求时的时间 
    %r First line of request,即表示请求报文的首行;记录了 此次请求的“方法”,“URL”以及协议版本 
    %>s 响应状态码 
    %b 响应报文的大小,单位是字节;不包括响应报文http首部 
    %{Referer}i 请求报文中首部“referer”的值;即从哪个页 面中的超链接跳转至当前页面的 
    Referer:可以防止其他公司链接自己网页的信息
    %{User-Agent}i 请求报文中首部“User-Agent”的值;即 发出请求的应用程序
    
    shift+F5:强行刷新网页,不使用缓存
    centos7:
    curl -i http://192.168.29.126/  头部加数据
    或links——>192.168.29.126 或 links 192.168.29.126  测试用
    网页打开,F12,network,headers,Referer
    vim /etc/httpd/conf/httpd.conf
    LogFormat "%h %t %u \"%{User-Agent}i\"" fenglog
    CustomLog logs/access_log fenglog  只能有一个CustomLog,所以其他注释掉
    !ser
    httpd -t
    tail -f /var/log/httpd/access_log
    设定默认字符集 
    AddDefaultCharset UTF-8 
    中文字符集:GBK, GB2312, GB18030 
    定义路径别名 
    格式: Alias  /URL/  "/PATH/" 
    vim /etc/httpd/conf/httpd.conf
    <Directory "/app/website1/bbs">
     Options indexes 
    </Directory>
    下面添加信息:alias /download /testdir/download/
    !ser
    httpd -t
    mkdir -p /testdir/download
    echo '<h1>welcome to huojia_fengzhuang</h1>' > /testdir/download/index.html
    浏览器:192.168.29.126/download/
    http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias  查看具体的alias帮助文档
    vim /etc/httpd/conf/httpd.conf
    alias信息更改为:AliasMatch ^/image/(.*)$ /ftp/pub/image/qiangge$1
    !ser
    httpd -t
    mkdir -p /ftp/pub/image/
    cp /etc/fstab /ftp/pub/image/qianggea.txt
    浏览器:192.168.29.126/image/a.txt
    /images
    /var/site1  /var/site2
    www.site1.com/images
    www.site2.com/images  二者都指向images
    
    
    
    image.png image.png image.png image.png image.png image.png
    基于用户的访问控制 
    rpm -qf `which htpasswd`
    rpm -ql httpd-tools
    自己规划把创建的账户放在/etc/httpd/conf.d/下面
    htpasswd -c /etc/httpd/conf.d/.htusers httpuser1
    htpasswd -s /etc/httpd/conf.d/.htusers httpuser2
    cat  /etc/httpd/conf.d/.htusers
    chmod 600  /etc/httpd/conf.d/.htusers
    setfacl -m u:apache:r /etc/httpd/conf.d/.htusers
    mkdir admin; cd admin/
    echo '<h1>welcome to henansheng_huojia_fengzhuang</h1>' > index.html
    cat index.html
    浏览器:192.168.29.126/admin/
    进行权限控制
    vim /etc/httpd/conf/httpd.conf
    <Directory "/app/website1/admin">
    authtype basic
    authname "admin directory"
    authuserfile "/etc/httpd/conf.d/.htusers"
    require user httpuser1 httpuser2
    </Directory>
    "require user httpuser1 httpuser2"更改为:require  valid-user  允许账号文件中的所有用户登录访问
    httpd -t
    !ser
    浏览器:192.168.29.126/admin/
    centos7:
    curl -I http://192.168.29.126/  可以访问
    curl -I http://192.168.29.126/admin  401身份验证
    vim /etc/httpd/conf/httpd.conf
    把信息更改为:
    <Directory "/app/website1/admin">
    allowoverride authconfig
    </Directory>
    cd /app/website1/admin
    vim .htaccess  哪个目录需要验证就放在哪个目录下;或者放在/etc/httpd/conf/下面
    authtype basic
    authname "admin directory"
    authuserfile "/etc/httpd/conf.d/.htusers"
    require valid-user
    !ser
    tail -f /var/log/httpd/access_log
    centos7:links 192.168.29.126/admin
    基于组账号进行认证 
    vim  /etc/httpd/conf.d/.htgroups
    group1:httpuser1 httpuser2
    group2:httpuser3
    cd /app/website1/admin
    vim .htaccess
    authtype basic
    authname "admin directory"
    authuserfile "/etc/httpd/conf.d/.htusers"
    authgroupfile "/etc/httpd/conf.d/.htgroups"
    require group group2
    !ser
    centos7:links 192.168.29.126/admin
    远程客户端和用户验证的控制 
    Satisfy ALL|Any 
    ALL 客户机IP和用户验证都需要通过才可以 
    Any客户机IP和用户验证,有一个满足即可 
    vim /etc/httpd/conf/httpd.conf
    搜索:/.htaccess
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </Files>
    例子:
    Require valid-user 
    Order allow,deny 
    Allow from 192.168.1 
    Satisfy Any
    
    
    第六讲
    虚拟主机
    cd /etc/httpd/conf
    cp httpd.conf.bak httpd.conf  还原主配置文件
    浏览器:192.168.29.126
    cd /etc/httpd/conf.d
    mv welcome.conf.bak welcome.conf
    浏览器:192.168.29.126
    vim /etc/httpd/conf/httpd.conf
    搜索:/conf.d/
    在/etc/httpd/conf.d/下实现虚拟主机
    
    基于IP的虚拟主机
    增加IP地址
    ip addr add 192.168.29.128/24 dev eth1 label eth1:1
    ip addr add 192.168.29.129/24 dev eth1 label eth1:2
    ip a
    centos7:ping 192.168.29.128/129
    cd /var/www/html
    echo "welcome to fgq_lol" > index.html
    浏览器:192.168.29.126/128/129
    建立3个网站,首先建立目录
    cd /app;ls
    cp -r website1/ website2
    cp -r website1/ website3
    tree
    cat website1/index.html:  <h1>welcome to website1</h1>
    vim website2/index.html:  <h1>welcome to website2</h1>
    vim website3/index.html:  <h1>welcome to website3</h1>
    让web服务器知道
    cd /etc/httpd/conf.d
    vim vhosts.conf  .conf结尾的文件即可
    参考/etc/httpd/conf/httpd.conf文件最下方的内容<VirtualHost *:80>进行编辑
    :r!tail -10 /etc/httpd/conf/httpd.conf
    <VirtualHost 192.168.29.126:80>  根据第一个来复制粘贴下面2个
        DocumentRoot /app/website1
        ServerName www.a.com  基于IP的虚拟主机,此行未生效
        ErrorLog logs/website1_error_log
        CustomLog logs/website1_access_log common
    </VirtualHost>
    <VirtualHost 192.168.29.128:80>
        DocumentRoot /app/website2
        ServerName www.b.com
        ErrorLog logs/website2_error_log
        CustomLog logs/website2_access_log common
    </VirtualHost>
    <VirtualHost 192.168.29.129:80>
        DocumentRoot /app/website3
        ServerName www.c.com
        ErrorLog logs/website3_error_log
        CustomLog logs/website3_access_log common
    </VirtualHost>
    httpd -t
    service httpd restart
    centos7:curl 192.168.29.126/128/129
    centos7:vim /etc/hosts  添加信息,进行解析即可
    192.168.29.126 www.a.com/www.aaa.com
    192.168.29.128 www.b.com
    192.168.29.129 www.c.com
    centos7:curl www.a.com/www.b.com/www.c.com/www.aaa.com都可以找到,和域名没关系,纯粹是通过IP找到的
    cd /var/log/httpd/; ls
    
    基于端口的虚拟主机
    注意启用非标准端口的时候,selinux需要禁用
    vim /etc/httpd/conf.d/vhosts.conf  
    根据前面做的实验,把端口更改一下,IP可以换成一样的,其他不变
    listen 8001
    listen 8002
    listen 8003
    <VirtualHost 192.168.29.126:8001>
        DocumentRoot /app/website1
        ServerName www.a.com
        ErrorLog logs/website1_error_log
        CustomLog logs/website1_access_log common
    </VirtualHost>
    <VirtualHost 192.168.29.126:8002>
        DocumentRoot /app/website2
        ServerName www.b.com
        ErrorLog logs/website2_error_log
        CustomLog logs/website2_access_log common
    </VirtualHost>
    <VirtualHost 192.168.29.126:8003>
        DocumentRoot /app/website3
        ServerName www.c.com
        ErrorLog logs/website3_error_log
        CustomLog logs/website3_access_log common
    </VirtualHost>
    service httpd restart
    ss -tnl
    grep -i listen /etc/httpd/conf/httpd.conf  80端口默认绑定在所有IP上
    centos7:curl www.aaa.com/www.b.com/www.c.com 都跳转到原来的主页面了,没有明确定义的,就走默认网站
    注意:一般虚拟机不要与main主机混用;因此,要使用虚拟主机, 一般先禁用main主机 
    禁用方法:注释中心主机的DocumentRoot指令即可
    centos7:curl www.aaa.com:8001/8002/8003
    
    以上两者不经常使用,经常使用的是FQDN
    基于FQDN(域名)的虚拟主机
    centos7:vim /etc/hosts  
    192.168.29.126 www.a.com www.b.com www.c.com  正常情况下,是要用dns来做的
    vim /etc/httpd/conf/httpd.conf
    搜索:/NameVirtualHost  
    vim /etc/httpd/conf.d/vhosts.conf
    NameVirtualHost *:80 或者 namevirtualhost *:80  添加此信息,更改一下IP和端口即可
    <VirtualHost *:80>
        DocumentRoot /app/website1
        ServerName www.a.com
        ErrorLog logs/website1_error_log
        CustomLog logs/website1_access_log common
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot /app/website2
        ServerName www.b.com
        ErrorLog logs/website2_error_log
        CustomLog logs/website2_access_log common
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot /app/website3
        ServerName www.c.com
        ErrorLog logs/website3_error_log
        CustomLog logs/website3_access_log common
    </VirtualHost>
    httpd -t 
    !ser
    centos7:curl www.a.com/www.b.com/www.c.com
    centos7:curl 192.168.29.126/128/129都是访问的webiste1
    以基于名字的虚拟主机,IP访问时,默认采用文件vhosts.conf定义的第一个虚拟主机
    通过IP地址找到主机,通过socket找到这个程序,socket文件是如何区分不同的网站的呢?如何知道谁是a,b,c呢?
    http协议里,socket就是IP地址+端口号,通过抓包软件,
    可以看出应用层的数据包里含有域名,即发出的请求里面含有域名。
    服务器根据应用层的信息可以返回相应的网页数据信息。
    centos7:telnet 192.168.29.126 80
    GET / HTTP/1.1
    HOST:WWW.B.COM/HOST:WWW.A.COM  返回的结果是完全不同的,
    以前是因为没有基于名字的虚拟主机,可以随便写的,返回默认结果即可。
    
    
    image.png
    status页面 
    vim /etc/httpd/conf/httpd.conf
    搜索:/Location 或者 /status
    vim /etc/httpd/conf.d/vhosts.conf  添加Location复制而来的信息,进行编辑
    namevirtualhost *:80
    <VirtualHost *:80>
        DocumentRoot /app/website1
        ServerName www.a.com
        ErrorLog logs/website1_error_log
        CustomLog logs/website1_access_log common
      <Location /server-status>
        SetHandler server-status
        Order deny,allow
        Deny from all
        Allow from all(更改了,其他不变)
      </Location>
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot /app/website2
        ServerName www.b.com
        ErrorLog logs/website2_error_log
        CustomLog logs/website2_access_log common
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot /app/website3
        ServerName www.c.com
        ErrorLog logs/website3_error_log
        CustomLog logs/website3_access_log common
    </VirtualHost>
    httpd -t
    service httpd restart
    浏览器:192.168.29.126/server-status
    centos7: links http://www.a.com/server-status
    centos7: curl 192.168.29.126/server-status
    centos7: ab -c 1000 -n 20000 192.168.29.126/server-status
    控制只有特定的域或者主机可以访问
    vim /etc/httpd/conf.d/vhosts.conf
    Location里面的Allow from all更改为Allow from 192.168.29.1
    centos7就不能访问,只有Windows可以访问
    centos7: links http://www.a.com/server-status不能访问
    浏览器:192.168.29.126/server-status可以访问
    vim /etc/httpd/conf/httpd.conf
    搜索:/status 
    vim /etc/httpd/conf.d/vhosts.conf
    ExtendedStatus On  放在虚拟主机外面,即VirtualHost最上面,
    不能在二者</VirtualHost>......<VirtualHost *:80>中间
    !ser
    浏览器:192.168.29.126/server-status显示内容更多
    
    
    image.png image.png image.png image.png image.png image.png
    看上图
    解决http协议无状态方法 
    cookie  客户端存放 
    session 服务端存放 
    googe浏览器——设置——高级——隐私设置和安全性——内容设置——cookie
    method: 请求方法,标明客户端希望服务器对资源执行的动作 
    telnet命令操作时,使用这些命令
    GET、HEAD、POST上传等
    CURL -I www.a.com:只要头部信息,相当于HEAD
    GET:从服务器获取一个资源 
    HEAD:只从服务器获取文档的响应首部 
    POST:向服务器输入数据,通常会再由网关程序继续处理——表单
    PUT:将请求的主体部分存储在服务器中,如上传文件——文件
    DELETE:请求删除服务器上指定的文档 
    TRACE:追踪请求到达服务器中间经过的代理服务器 
    OPTIONS:请求服务器返回对指定资源支持使用的请求方法
    协议查看或分析的工具: tcpdump, wireshark,tshark
    tcpdump -i eth1 -nn -v
    wireshark需要下载
    status(状态码): 
    1xx:100-101 信息提示 
    2xx:200-206 成功 
    3xx:300-305 重定向   centos7:curl -I http://www.360buy.com或http://www.jd.com
    4xx:400-415 错误类信息,客户端错误 
    5xx:500-505 错误类信息,服务器端错误
    200: 成功,请求数据通过响应报文的entity-body部分发送;OK 
    301: 请求的URL指向的资源已经被删除;
    但在响应报文中通过首部 Location指明了资源现在所处的新位置;Moved Permanently 
    302: 与301相似,但在响应报文中通过Location指明资源现在所处 临时新位置; Moved Temporarily 
    304: 客户端发出了条件式请求,但服务器上的资源未曾发生改变 ,则通过响应此响应状态码通知客户端;Not Modified 
    401: 需要输入账号和密码认证方能访问资源;Unauthorized 
    403: 请求被禁止;Forbidden 
    404: 服务器无法找到客户端请求的资源;Not Found 
    500: 服务器内部错误;Internal Server Error 
    502: 代理服务器从后端服务器收到了一条伪响应,如无法连接到父网关;Bad Gateway
    tail /var/log/httpd/access_log  里面的地址是IP层的地址,有可能是代理服务器的IP,而不是真正的客户端的IP
    
    image.png
    curl工具 
    curl是基于URL语法在命令行方式下工作的文件传输工具,
    它支持FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE及LDAP等协议。
    curl支持HTTPS认证,并且支持 HTTP的POST、PUT等方法, FTP上传, kerberos认证, HTTP上传,代理服务器,
    cookies,用户名/密码认证,下载文件断点续传,上载文件断点续传,
    http代理服务器管道( proxy tunneling),还支持IPv6,socks5代理服务器,
    通过http代理服务器上传文件到FTP服务器等,功能十分强大 
    vim /etc/httpd/conf.d/vhosts.conf  
    CustomLog logs/website1_access_log common
    common变为combined
    !ser
    tail -f  /var/log/httpd/website1_access_log
    centos7: curl -A "IE9" http://www.a.com/  设置用户代理发送给服务器,伪造使用哪个浏览器访问
    centos7: curl -e "http://www.baidu.com" http://www.a.com/  来源网址,伪造从哪个网站跳转过来
    centos7: curl --compressed http://www.a.com/  要求返回是压缩的格式,需要配置文件里启用此功能模块,否则不能使用
    centos7: curl -H "host:www.b.com" http://www.a.com  自定义首部信息传递给服务器 
    访问的是website2,不是website1,因为指定了host
    centos7: curl -i http://www.a.com/  实体和头部信息都显示
    centos7: curl -I http://www.a.com/  只显示头部信息
    centos7: curl -D header http://www.a.com;cat header  将url的header信息存放在指定文件中 
    vim /etc/httpd/conf.d/vhosts.conf
    <Directory /app/website1/admin>  添加到主机1 virtualhost里面
        allowoverride authconfig
    </Directory>
    !ser
    centos7: curl --basic -u httpuser3:123456 www.a.com/admin  出现301跳转页面
    -u/--user <user[:password]>  设置服务器的用户和密码
    centos7: curl -o bb.txt www.a.com/b.html; cat bb.txt  将网络文件保存为指定的文件中 
    centos7: curl -O www.a.com/b.html  使用URL中默认的文件名(b.html)保存文件到本地 
    centos7: curl -o bb.html --limit-rate 30 www.a.com/b.html   30个字节的传输
    --limit-rate  设置传输速度  有时候需要限速,以防止拖垮服务器
    centos7: curl -0 www.a.com  使用HTTP 1.0
    
    -L  选项进行强制重定向 
    -C - 选项可对文件使用断点续传功能 
    -c/--cookie-jar <file name> 将url中cookie存放在指定文件中 
    -x/--proxy <proxyhost[:port]> 指定代理服务器地址 
    -U/--proxy-user <user:password> 代理服务器用户和密码 
    -T 选项可将指定的本地文件上传到FTP服务器上 
    --data/-d 方式指定使用POST方式传递数据 
    
    elinks工具: links
    links -dump www.a.com  不进入交互式模式,而直接将URL的内容输出至标准输出 
    elinks -source www.a.com  打印源码
    玩:
    links -dump www.jd.com
    links -dump 网址   可以下载网页上面的文字或者内容(博客,书籍,商城...)
    
    
    image.png
    使用mod_deflate模块压缩页面优化传输速度 
    cp  /var/log/httpd/access_log  /app/website1/a.txt  准备一个大文件
    centos7:  curl -I www.a.com/a.txt
    centos7:  curl --compressed -I www.a.com/a.txt  未启用此模块,未压缩
    vim /etc/httpd/conf/httpd.conf
    搜索:/deflate  看此模块是否加载
    LoadModule deflate_module modules/mod_deflate.s  表示加载
    vim /etc/httpd/conf.d/vhosts.conf
    在最下面添加信息:
    SetOutputFilter DEFLATE  启用压缩
    DeflateCompressionLevel 9  压缩比
    # Restrict compression to these MIME types 
    AddOutputFilterByType DEFLATE text/plain 
    AddOutputFilterByType DEFLATE text/html 
    AddOutputFilterByType DEFLATE application/xhtml+xml 
    AddOutputFilterByType DEFLATE text/xml 
    AddOutputFilterByType DEFLATE application/xml 
    AddOutputFilterByType DEFLATE application/x-javascript 
    AddOutputFilterByType DEFLATE text/javascript 
    AddOutputFilterByType DEFLATE text/css
    service httpd restart
    curl --compressed -I www.a.com/a.txt
    curl -I www.a.com/a.txt  比较Content-Length的大小即可
    
    
    image.png
    https
    yum -y install mod_ssl  配置httpd支持使用ssl,及使用的证书  
    配置文件:/etc/httpd/conf.d/ssl.conf 
    rpm -ql mod_ssl
    cd /etc/httpd/conf.d; httpd -M |grep ssl
    service httpd restart
    浏览器:https://192.168.29.126——高级——继续访问
    F12——Security——View certificate——详细信息——复制文件——下一步——下一步——保存在桌面a文件——完成
    增加信任:设置——高级——管理证书——受信任的根证书颁发机构——导入——下一步——把桌面下载的a文件导入——
    下一步——浏览栏中,选择:受信任的根证书颁发机构——完成——是
    
    颁发证书
    centos7.3——客户端
    centos6.9——web服务器
    centos6-3——CA
    centos6-3操作
    cd /etc/pki/tls/
    vim openssl.cnf  复制下面的内容
    dir             = /etc/pki/CA           # Where everything is kept
    certs           = $dir/certs            # Where the issued certs are kept
    crl_dir         = $dir/crl              # Where the issued crl are kept
    database        = $dir/index.txt        # database index file.
    #unique_subject = no                    # Set to 'no' to allow creation of
                                            # several ctificates with same subject.
    new_certs_dir   = $dir/newcerts         # default place for new certs.
    
    certificate     = $dir/cacert.pem       # The CA certificate
    serial          = $dir/serial           # The current serial number
    crlnumber       = $dir/crlnumber        # the current crl number
                                            # must be commented out to leave a V1 CRL
    crl             = $dir/crl.pem          # The current CRL
    private_key     = $dir/private/cakey.pem# The private key
    RANDFILE        = $dir/private/.rand    # private random number file
    
    x509_extensions = usr_cert              # The extentions to add to the cert
    cd /etc/pki/CA
    (umask 066 ;openssl genrsa -out private/cakey.pem 1024)  私钥
    openssl req -new -x509 -key private/cakey.pem -out cacert.pem  自己给自己是509
    CN,henan,zhengzhou,magedu.com,IT,ca.magedu.com,回车  邮箱不用了
    ll
    sz cacert.pem  传到Windows里,打开下载,把文件后缀改为cacert.crt,默认时间为1个月,更改为1年,date
    centos6操作
    cd /etc/httpd/conf.d; mkdir ssl; cd ssl; 
    (umask 066 ;openssl genrsa -out httpd.key 1024)
    openssl req -new -key httpd.key -out httpd.csr
    CN,henan,xinxiang,magedu.com,IT,www.a.com,回车,回车,回车
    ll
    scp httpd.csr 192.168.29.132:/etc/pki/CA/  此IP地址是centos6-3的IP
    如果centos6-3的scp命令没有安装需要安装,否则即使本机有scp命令也传不过去
    yum -y install openssh-clients
    centos6-3操作:颁发证书
    cd /etc/pki/CA; ls
    echo 01 > serial 
    touch index.txt
    openssl ca -in httpd.csr -out certs/httpd.crt -days 10
    y, y
    ls newcerts/; ls certs/
    scp certs/httpd.crt 192.168.29.126:/etc/httpd/conf.d/ssl
    scp cacert.pem 192.168.29.126:/etc/httpd/conf.d/ssl
    scp cacert.pem 192.168.29.127:   传到根下面了
    centos6操作:
    cd /etc/httpd/conf.d/ssl; ll
    cd /etc/httpd/conf.d/
    rpm -q --scripts mod_ssl  
    vim ssl.conf
    SSLCertificateFile /etc/httpd/conf.d/ssl/httpd.crt
    SSLCertificateKeyFile /etc/httpd/conf.d/ssl/httpd.key
    SSLCACertificateFile /etc/httpd/conf.d/ssl/cacert.pem
    service httpd restart
    centos7:  firefox https://192.168.29.126
    浏览器:https://192.168.29.126
    不信任,和上一回生成证书的步骤相同,来生成证书
    修改Windows的host文件:win键+r:  c:\Windows\System32\drivers\etc
    在host文件的最下面添加信息:192.168.29.126 www.a.com 
    
    centos7图形界面的命令行:  firefox https://192.168.29.126
    centos7图形界面的命令行:  firefox https://www.a.com
    centos7:  curl --cacert cacert.pem https://www.a.com
    centos7:  curl -k https://192.168.29.126  -k忽略证书
    centos7:  openssl s_client -connect www.a.com:443  模拟图形界面的浏览器访问
    googel:  https://192.168.29.126 或者 https://www.a.com  可以访问
    搜狗:  https://192.168.29.126 或者 https://www.a.com  可以访问
    IE浏览器不能访问
    vim /etc/httpd/conf.d/ssl.conf
    在文件的<VirtualHost _default_:443>下面添加信息:
    DocumentRoot /app/website1 
    把ServerName更改为:ServerName www.a.com:443  使用的是虚拟主机要更改,默认网站则不用更改
    googel:  https://192.168.29.126/a.txt 或者 https://www.a.com/a.txt  可以访问
    搜狗:  https://192.168.29.126/a.txt 或者 https://www.a.com/a.txt  可以访问
    
    vim /etc/httpd/conf.d/vhosts.conf
    Redirect temp / https://www.a.com/  添加到虚拟主机website1里面
    service httpd restart
    centos7图形界面的命令行:  firefox http://www.a.com  会跳转至:https://www.a.com
    此访问是通过服务器跳转,需要经过网络,也不是很安全,
    最好是用户访问的时候,直接就是https网站,这需要用到HSTS,下面内容就是
    
    image.png
    HSTS
    服务器端配置支持HSTS后,会在给浏览器返回的HTTP首部中携带 HSTS字段。
    浏览器获取到该信息后,会将所有HTTP访问请求在内部 做307跳转到HTTPS。而无需任何网络过程 
    vim /etc/httpd/conf.d/vhosts.conf
    删除此行信息:Redirect temp / https://www.a.com/  
    并添加下面的信息到虚拟主机website1里面
    Header always set Strict-Transport-Security "maxage=15768000"  秒为单位
    RewriteEngine on 
    RewriteRule ^(/.*)$  https://%{HTTP_HOST}$1 [redirect=301]
    service httpd restart
    centos7:  curl -I http://www.a.com  301跳转
    centos7图形界面的命令行:  firefox http://www.a.com  跳转至https
    centos7:  curl -I http://www.jd.com
    
    命令工具
    ab -c 2000 -n 29999 http://www.a.com/  不能执行,打开的文件过多,受限制
    ulimit -a  打开的文件数是1024
    ulimit -n 60000  设定打开的文件数量是60000  调整能打开的文件数
    ab -c 2000 -n 29999 http://www.a.com/  能执行
    apachectl:httpd自带的服务控制脚本,支持start和stop,相当于service
    ab  [OPTIONS]  URL 
    httpd-tools包 
    -n:总请求数 
    -c:模拟的并行数 
    -k:以持久连接模式测试 
    tcpcopy:网易,复制生产环境中的真实请求,并将之保存 
    
    
    image.png image.png

    相关文章

      网友评论

        本文标题:HTTP

        本文链接:https://www.haomeiwen.com/subject/vtvyxftx.html