• nginx内容


    nginx工作在7层:web server(静态内容 static contents)web reverse proxy(反向代理http,https,mail),cache(带缓存功能)

    proxy(反向代理http,https,mail),cache(带缓存功能)
    varnish,squid (cache),web,http headers
    haproxy:基于应用层和tcp层的反向代理,http revers proxy
    keeplived:HA
    ats:apache traffic server

    响应码

    1XX
    2XX:成功响应码
    200
    3XX:重定向
    301
    302
    304
    4XX:客户端错误
    5XX:服务器端错误

    keepalive: (在http 1.0就支持长连接渲染也叫保持连接) 这个功能作用是,我们在请求一个web站点的时候,有许多web object(图片 js 等),每次请求资源,都需要三次握手,四次断开,所有就有keepalive,当一个资源传输资源结束后TCP连接不断开,能够同一个TCP通道上面允许用户继续发起请求;
    keepalive不能无限制的一直连接着,有下面2个限定断开方式
    keepalive 时间:timeout
    keepalive 数量:

    web I/O模型

    同步
    阻塞
    非阻塞
    I/O复用
    select(),
    poll()
    prefork:基于select()

    并发编程)处理并发用户请求:
    单进程模型:串行方式模式
    多进程模型:prefox,一个进程响应一个用户请求,并发使用多个进程实现
    多线程模型:worker,一个进程生成多个线程,一个线程响应一个用户请求;并发使用多个线程实现:n进程,n*m个线程
    线程(事件)模型:event。一个线程响应多个用户请求,基于事件驱动机制来维持多个用户请求

     nginx的特性:

    基本功能:
    实现与服务静态文件(静态资源的web服务器),能缓存打开的文件描述符
    反向代理服务器,缓存、负载均衡、健康状态检测
    支持FastCGI
    模块化机制,非DSO机制,支持多种过滤器gzip,SSI和图像的模块完成图形大小调整等
    支持SSL

    扩展功能:

    基于名称和IP做虚拟主机
    支持keeplive
    支持平滑配置更新或程序版本升级
    定制访问日志,支持使用日志缓存以提高性能
    支持URL rewrite
    支持路径别名
    支持基于IP及用户的认证:
    支持速率限制,并发数限制等

    nginx的基本架构

    一个master 生成一个或多个worker
    事件驱动:kqueue,epoll,/dev/poll
    消息通知:select,poll,rt rignals
    支持sendfile,sendfile64
    文件AIO(异步I/O)
    支持mmap

    nginx:非阻塞、事件驱动,一个master多个worker,一个worker响应多个用户请求

    nginx的模块类别
    核心模块
    标准http模块
    可选的http模块
    邮件模块
    第三方扩展模块


    安装方法:

    编译安装
    rpm包安装
    epel源

    Nginx的配置文件

            main配置段(核心配置)

    http{

    }
    mail{

    }

    配置参数需要以分号结尾,语法格式:
    参数名 值1[值2...];

    还支持使用变量
    模块内置变量
    用户自定义变量
    set var_name value

    Modules

     

    Contents

     [hide

    Installing Modules

    Nginx modules must be selected during compile, run-time selection of modules is not currently supported.

    A full summary of the compile-time options, including optional modules, can be found in the provided configure script by running ./configure --help

    Nginx core module

    This module is required.

    NameDescription
    Core Configure error logging, processes, permissions, epoll/kqueue/select/poll events, etc.

    Standard HTTP modules 标准模块默认被安装了,如果不需要安装--without

    These modules are automatically compiled in unless explicitly disabled with configure.

    NameDescriptionVersionconfigure argument to disable
    HTTP Core Control ports, locations, error pages, aliases, and other essentials.   --without-http
    Access Allow/deny based on IP address.   --without-http_access_module
    Auth Basic Basic HTTP authentication.   --without-http_auth_basic_module
    Auto Index Generates automatic directory listings.   --without-http_autoindex_module
    Browser Interpret "User-Agent" string. 0.4.3 --without-http_browser_module
    Charset Recode web pages.   --without-http_charset_module
    Empty GIF Serve a 1x1 image from memory. 0.3.10 --without-http_empty_gif_module
    FastCGI FastCGI Support.   --without-http_fastcgi_module
    Geo Set config variables using key/value pairs of IP addresses. 0.1.17 --without-http_geo_module
    Gzip Gzip responses.   --without-http_gzip_module
    Headers Set arbitrary HTTP response headers.  
    Index Controls which files are to be used as index.  
    Limit Requests Limit frequency of requests from a client. 0.7.20 --without-http_limit_req_module
    Limit Conn Limit concurrent active connections based on a variable.   --without-http_limit_conn_module
    Log Customize access logs.  
    Map Set config variables using arbitrary key/value pairs. 0.3.16 --without-http_map_module
    Memcached Memcached support.   --without-http_memcached_module
    Proxy Proxy to upstream servers.   --without-http_proxy_module
    Referer Filter requests based on Referer header.   --without-http_referer_module
    Rewrite Request rewriting using regular expressions.   --without-http_rewrite_module
    SCGI SCGI protocol support. 0.8.42 --without-http_scgi_module
    Split Clients Splits clients based on some conditions 0.8.37 --without-http_split_clients_module
    SSI Server-side includes.   --without-http_ssi_module
    Upstream For load-balancing.   --without-http_upstream_ip_hash_module (ip_hash directive only)
    --without-http_upstream_least_conn_module (least_conn directive only)
    --without-http_upstream_keepalive_module (keepalive directive only)
    User ID Issue identifying cookies.   --without-http_userid_module
    uWSGI uWSGI protocol support. 0.8.40 --without-http_uwsgi_module
    X-Accel X-Sendfile-like module.    

    Optional HTTP modules 选项模块默认没被安装,需要安装--with-xxx安装进入nginx

    The following modules must be enabled at compile-time with the specified option to configure.

    NameDescriptionVersionconfigure argument to enable
    Addition Append text to pages.   --with-http_addition_module
    Auth Request Implements client authorization based on the result of a subrequest. 1.5.4 --with-http_auth_request_module
    Degradation Allow to return 204 or 444 code for some locations on low memory condition. 0.8.25 --with-http_degradation_module
    Embedded Perl Use Perl in Nginx config files. 0.3.21 --with-http_perl_module
    FLV Flash Streaming Video 0.4.7 --with-http_flv_module
    GeoIP Creates variables with information from the MaxMind GeoIP binary files. 0.8.6, 0.7.63 --with-http_geoip_module
    Google Perftools Google Performance Tools support. 0.6.29 --with-google_perftools_module
    Gzip Precompression Serves precompressed versions of static files. 0.6.23 --with-http_gzip_static_module
    Gunzip On-the-fly decompressing of gzipped responses. 1.3.6 --with-http_gunzip_module
    Image Filter Transform images with Libgd 0.7.54 --with-http_image_filter_module
    MP4 Enables mp4 streaming with seeking ability. 1.1.3, 1.0.7 --with-http_mp4_module
    Random Index Randomize directory indexes. 0.7.15 --with-http_random_index_module
    Real IP For using nginx as backend 0.3.8 --with-http_realip_module
    Secure Link Protect pages with a secret key. 0.7.18 --with-http_secure_link_module
    SPDY SPDY protocol support. 1.3.15 --with-http_spdy_module
    SSL HTTPS/SSL support.   --with-http_ssl_module
    Stub Status View server statistics. 0.1.18 --with-http_stub_status_module
    Substitution Replace text in pages   --with-http_sub_module
    WebDAV WebDAV pass-through support. 0.3.38 --with-http_dav_module
    XSLT Post-process pages with XSLT. 0.7.8 --with-http_xslt_module

    Mail modules 

    NameDescriptionconfigure argument
    Mail Core Core parameters for mail module. --with-mail
    POP3 POP3 settings. --without-mail_pop3_module
    IMAP IMAP settings. --without-mail_imap_module
    SMTP SMTP settings. --without-mail_smtp_module
    Auth HTTP Use Nginx to authenticate mail services.
    Proxy Nginx can proxy IMAP, POP3, and SMTP protocols.
    SSL This module ensures SSL/TLS support for POP3/IMAP/SMTP. --with-mail_ssl_module

    Obsoleted articles

    Most of the links above points to official up-to-date documentation provided by Nginx, Inc. For historical reasons there is a list of obsoleted wiki articles.

    WARNING: these articles may contain outdated, incomplete or even incorrect information.

    Please always refer to the official documentation avaiable at http://nginx.org.

    Third party modules and Patches

    Please see the catalog of 3rd party modules.

    References

    开始安装

    PCRE库(Nginx的rewrite模块和HTTP核心模块会用到PCRE正则表达式语法)

    yum install pcre pcre-devel

    ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/tmp/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/client --http-proxy-temp-path=/var/tmp/proxy --http-fastcgi-temp-path=/var/tmp/fastcgi --http-uwsgi-temp-path=/var/tmp/uwsgi --http-scgi-temp-path=/var/tmp/scgi --with-pcre | tee /opt/nginx_install

    ###

      --http-client-body-temp-path  处理http请求时,http的包体需要暂时存储放在目录文件中(放到磁盘中);为什么要这么放,如果2000个并发,都需要上传文件,每个文件假如200M,这时候就超过内存使用量了,这时候我就需要暂时存在磁盘上(工作模式nginx 全部接收完后,在全部返回给上游服务器)

           --http-proxy-temp-path nginx作为反向代理服务器;后端实体工作机(上游服务器)包体需要存放的临时文件时使用的目录(工作模式nginx 全部接收完后,在全部返回给用户)

     Nginx基本核心配置的类别

    用于调试、定位问题
    正常运行的必备配置
    优化性能的配置
    事件类的配置

    worker进程应该以普通用户身份运行。nginx用户,nginx组
    http的方法:GET,HEAD,POST,PUT,DELETE OPTIONS TRACE

    nginx的配置:

     

      核心配置

      1 正常运行的必备配置

        1 user username [groupname];   指定运行worker进程的用户和组

        2 pid 路劲;  指定nginx的pid文件路劲

        3 worker_rlimit_nofile;  指定一个worker进程打开的最大文件数(也就是一个worker并发数)

        4 worker_rlimit_sigpending;  设定每个用户能够发往woker进程的信号的数量

      2 优化性能相关的配置

        1 worker_processes 4;  worker进程的个数(通常其数值应为为CPU物理核心数减1)

        2 worker_cpu_affinity  0000 0001 0010  0100 (CPU掩码);   CPU倾源性;让worker进程必须运行在某颗CPU,这样的好处可以避免上下文切换,不会在其他CPU上面挑来跳去的(0000表示绑定第一个cpu上面; 0001表示绑定第二个cpu上面  0011表示使用CPU第0颗和第一颗)

        3 ssl_engine device;  有些服务器自带ssl加速硬件,在存在ssl硬件加速器的服务器上面,执行使用的ssl硬件加速设备

        4 timer_resolution 100ms;  每次内核事件调用返回时;都会使用gettimeofday()来更新nginx缓存时钟;但是gettimeofday()调用代价太大,timer_resolution表示就是不管你调用多少次,我多长时间返回一次(timer_resolution用于定义每隔多久才会由gettimeday()更新一次缓存时钟;x86-64系统上,gettimeday()代价已经很小,可以忽略此配置)

        5 worker_priority -10;  worker进程的优先级(-20到19之间的值,值越小越优先调用)  

      3 事件相关的配置

        1 accept_mutex [on|off];  是否打开nginx的负载均衡锁(默认开启);此锁能够让多个worker进行轮流地、序列化地与新的客户端建立连接;而通常当一个worker进程的负载达到其上限的7/8,master就尽可能不将请求调度至worker

        2 lock_file /path/to/lock_file;  锁文件

        3 accept_mutex_delay #ms;  使用accept锁以后,只有一个worker能取得锁,一个worker进程为取得accept锁的等待时长,即用户建立等待的时间,如果某worker进程在某次试图取得锁时失败了,至少要等待#ms才能在一次请求锁(默认500ms)

        4 multi_accept [on|off]  是否允许一次性地响应多个用户请求,默认为off

        5 use [epoll|rtsig|select|poll]  指定使用那种模型,建议让nginx自动选择

        6 worker_commections #; 每个worker能够并发响应的最大请求数,如果为代理服务器的话,worker_rlimit_nofile=worker_commections*2 

      3 用于调试、定位问题:只调试nginx时使用

        1 daemon on|off;  关闭提供守护进程的模式,是否让nignx运行于后台;调试时应该为off,使得所有信息直接输出在控制台,默认为on

        2 master_process on|off;  是否以master/worker模式运行nginx,默认为on,调试时可以设置为off以方便追踪

        3 error_log /path/error_log level;  (错误日志是全局的,在核心配置中,访问日志是在虚拟主机中配置)错误日志文件及其级别,调试时可以使用debug级别,但要求在编译时必须使用--with-debug启用debug功能,默认通常为error级别

      nginx的http web功能

      1 nginx必须使用虚拟机来配置站点:每个虚拟主机使用一个server{ }段来配置     

        server {

        }

      2 非虚拟主机的配置和公共选项,需要定义在server之外,http之内,也就是说http的配置对所有里面的server都有效(配置虚拟主机的相关参数,一个http中可以有多个server)

        http{
          directive value;
          ....

          server{

            }
          server{

            }
            ......
            }

      1 server{ }  定义一个虚拟主机:nginx支持使用基于主机名或IP的虚拟主机

      2 listen 支持3种方式

        1 listen address[:port]   2 listen prot(所有地址)  3 listen unix:socket_file_path

      

        3 default_server:  定义此server为http中默认的server;如果所有的server中任何一个listen使用此参数,那么第一个server即为默认server

        

     

        4 rcvbuf=SIZE:  接收缓存大小  sndbuf=SIZE: 发送缓存大小  ssl:https server:必须以ssl连接

        5 server_name [...];  server_name可以跟多个主机名,名称可以使用通配符和正则表达式(通常以~开头):当nginx收到一个请求时,会取出其首部的server的值,而后跟众server_name进行比较:比较方式

                   (1) 先做精确匹配:www.1212.com  (2) 左侧通配符匹配*.1212.com  (3) 右侧通配符匹配:www.*  (4) 正则表达式匹配:~^.*.2121.com$

        6 server_name_hash_bucket_size 32|64|128  为了实现快速主机查找,nginx使用hash表来保存主机名

        7 location 两种使用格式 location [ =|~|~*|^~] uri { ... }  和 location @name { ... }  功能:允许根据用户请求的URI来匹配指定的各location以进行访问配置;匹配到时,将被location块中的配置所处理(写在server里面或者单独location写在外面).比如:当用户请求 http://www.baidu.com/img/a.png,这时候/img/a.png会匹配location 中的uri做相应的处理  

          =:精确匹配

          ~:正则表达式模式匹配,匹配时区分字符大小写

          ~*:正则表达式模式匹配,匹配时忽略字符大小写

          ^~:只需要前半部分与uri匹配即可,不检查正则表达式

    location = / {
      [ configuration A ]
    }

    location / {
      [ configuration B ]
    }

    location /documents/ {
      [ configuration C ]
    }

    location ^~ /images/ {
      [ configuration D ]
    }

    location ~* .(gif|jpg|jpeg)$ {
      [ configuration E ]
    }

          http://www.bbb.com/  configuration A

          http://www.bbb.com/img  configuration B

          http://www.bbb.com/documents/a.sh  configuration C      

          匹配优先级:

            字符字面量最精确匹配、正则表达式检索(如果有多个正则能匹配时,由第一个匹配到的所处理),如果没有正则表达式按字符字面量

          location 指令:

    文件路径定义
      1.root path    

    location ^~/img {
      root /web;     #需要使用http://192.168.111.128/img/a.html访问; 访问的是web目录下面有个img目录下的文件 
    }

             
    设置web资源路径,用于指定请求的根文档目录,从跟开始匹配
      root:root/URI
      2.alias path
    指定路径别名,只能用于location中,从最后一个/开始匹配
      alias:alias/

    location ^~/img {
      alias /web;     #需要使用http://192.168.111.128/img/a.html访问; 其实就是web的别名就是img  
    }

         

      3.index file....
    定义默认页面,可以跟多个值。自左向右匹配
      4.error_page code ... [=[response]] uri

          error_page  404              /404.html;   #错误代码为404的时候,就返回404页面

          error_page  404 =200             /404.html;   #错误代码为404的时候,就返回404页面,并且返回200的状态码,日子里面能看到响应是200了


    当对于某个请求发回错误时,如果匹配上了error_page指令中设定的code,则从定向至新的新URI中
    错误重定向
      5.try_files path1 [path2...] uri;
    自左向右尝试读取有path所指定路径,在第一找到即停止并返回,如果所有path均不存在,则返回最后一个uri
      location ~* ^/document/(.*)${
          root /www/htdocs
          try_files $uri /docu/$1 /temp.html    #$uri = document     $1分组=(.*)
        }

         8 网络连接相关的设置      

    1.keepalive_timeout time;   保持连接的超时时长,默认为75s
    2.keepalive_requests n;    在一次长连接上允许承载的最大请求数
    3.keepalive_disable [msie6|safari |none]    对指定的浏览器禁止使用长连接
    4.tcp_nodelay on|off    对keepalive连接是否使用tcp_nodelay选项
    5.client_header_timeout time    读取http请求首部的超时时长
    6.client_body_timeout time    读取http请求包体的超时时间
    7.save_timeout time    发送响应的超时时长

     

        9 对客户端请求的限制:

    1.limit_except method ...{ ... }  指定范围之外的其他方法的访问控制,只能用于location中,limit_except的意思是”限制除了“也就是允许啦。
    location /doc {
      root /web;
      try_files $uri /doc/tmp.html;
      limit_except POST{
      allow 127.0.0.1;
      deny all;
      }
    }

    2.client_max_body_size size http  请求包体的最大值,常用于限定客户端所能够请求的最大包体,根据请求首部中的Content-Length来检查,以避免无用的传输

    3.limit_rate speed  限制客户端每秒传输的字节数,默认为0,表示没有限制
    4.limit_rate_after time  nginx向客户端发送响应报文时,如果时长超过了此处指定的时长,则后续的发送过程开始限速

        10 文件操作的优化

    1.sendfile on|off  是否启用sendfile功能
    2.aio on|off  是否启用aio功能
    3.open_file_cache man=N [incative=time]|off  是否打开文件缓存功能

     

      11 http核心模块的内置变量:

    $uri:当前请求的uri,不带参数
    $request_uri:请求的uri,带完整参数
    $host:http请求报文中host首部;如果请求中没有host首部,则以处理此请求的主机的主机名代替
    $hostname:nginx服务运行所在主机的主机名
    $remote_addr:客户端IP
    $remote_port: 客户端port
    $remote_user:使用用户认证时客户端用户输入的用户名
    $request_filename:用户请求中的URI经过本地root或alias转换后映射的本地的文件路径
    $request_method:请求方法
    $server_addr:服务器地址
    $server_name: 服务器名称
    $server_port:服务器端口
    $server_protocol:服务器向客户端发送响应时的协议,如http/1.1,http/1.0
    $scheme:在请求中使用的scheme 映射协议本身的协议
    $http_HEADER:匹配请求报文中指定的HEADER,例如$http_host匹配请求报文中的host首部
    $sent_http_HEADER:匹配响应报文中指定的HERDER,例如$http_content_type匹配相应报文中的content-type首部
    $document_root:当前请求映射到的root配置

    开始使用nginx

      1.nginx虚拟主机

    server {
      listen 80;
      server_name www.a.com;
      location / {
        root /web;
      }
    }

     

    2 访问控制access模块

    server {
      listen 80;
      server_name www.b.com 127.0.0.1;
      allow 127.0.0.1;  
      deny all;
      location / {
        root /web;
      }
    }

     

    3.基于用户认证 

    server {
      listen 80;
      server_name www.d.com;
        location /admin/ {
        auth_basic "admin run";  #标题
        auth_basic_user_file /web/.htpasswd;  #生成密码文件  htpasswd -c -m /web/.htpasswd admin 
        root /web;
      }
    }

      

      4. 建立下载站点autoindex下载列表 

      location /download/ {
        root /web;
        autoindex on; #列出当前目录下面所有的文件
      }

      

      5.防盗链  

      (1) 定义和规定额引用
        valid_referers none |blocked |server_names|string ...
      (2) 判断不合规的引用

        

        if ($invaild_referer) {
          rewrite ^/.*$ http://www.a.com/403.html
        }

       

      6.url重写 rewrite

        (比如访问的是a.com跳转b.com,又例如我们的图片都放在在img目录,后来改了放到image目录,外部的程序访问还是img目录,这时候rewrite我们就需要把他改成image目录)

      rewrite regex replacement [flag];

      location / {
        root /web;
        rewrite ^/imgages/(.*)$  /imgs/$1 last;  #$1是前面的(.*)$分组内容;访问根下面的imgages替换成imgs
      }
       

      server {
        listen 80;
        server_name www.a.com;
        location /a/ {
        root /web/;
        rewrite ^/a/(.*.(jpg|gif))$ /img/$1 break;  #web目录下面有a和img目录;img有图片文件;访问http://www.a.com/a/a.jpg 会重定向到/img/a.jpg ;(测试last报404错误 用break解决)
          }
        }
       }

      

      server {
        listen 80;
        server_name www.a.com;
        location /a/ {
          root /web/;
          rewrite ^.*$ http://www.baidu.com last;  #跳转到百度
        }
      }


      flag:标志位
        last:一旦被当前规则匹配并重写后立即停止检查后续饿的其他rewrite的规则,而后通过重写后的规则重新发起请求(继续向下匹配新的location URI规则)
        break:一旦被当前规则匹配并重写后立即停止检查后续的其他rewrite的规则,而后继续由nginx进行后续的操作
        redirect:返回302临时重定向代码
        permanent:返回301永久重定向

     

      nginx最多循环10次,超出之后返回500错误

      里面的括号不需要转义的
      注意:一般将rewrite写在location中时都使用break标志,或者将rewrite卸载if上下文中

      rewrite_log on|off

        是否将重写过程记录在错误日志中,默认为notice级别;默认为off

      return code:  

        server {
          listen 80;
          server_name www.a.com;
          location /a/ {
          root /web/;
          return 403;  #返回403错误
            }
          }
         }

        用于结束rewrite规则,并且为客户返回状态码:可以使用的状态码有204,400,402-406,500-504等


      if (condition) {

      }
        用于检测条件是否成立

      

      7.状态页
      location{
        stub-status on
        }

        当下处于活动状态的总数

        接受的总数 已经建立和处理总数 请求的总数

      正在接受的并发请求个数,正在读取的个数或发往客户端的 ,长连接中的处于活动状态的值


      8.压缩:
        gzip
        gzip on|off
        gzip_buffer 使用的缓存大小
        gzip_comp_level 压缩的级别
        gzip_disable 不压缩的类型或浏览器
        gzip_min_length 最少压缩的大小
        gzip_http_version 压缩完成以后发送http的版本
        gzip_types:只压缩的格式

     

    if 判断语句:

      在location中使用if语句可以实现条件判断,通常有一个return语句,并且一般与有着last 或者 break标记的rewrite规则一同使用.但其也可以使用在多种环境下,需要注意的是,不当的使用可能会导致不可预料的后果.

      location / {

             if ($reuest_method == "PUT"){

          proxy_pass http://www.a.com:9090;

        } 

        }

      location / {

             if ($reuest_uri ~ ".(jpg|gif)$"){

          proxy_pass http://www.a.com:9090;

          break;

        } 

        }

    一、if语句中的判断条件(nginx)

    1、正则表达式匹配:

    ==:等值比较;

    ~:与指定正则表达式模式匹配时返回“真”,判断匹配与否时区分字符大小写;

    ~*:与指定正则表达式模式匹配时返回“真”,判断匹配与否时不区分字符大小写;

    !~:与指定正则表达式模式不匹配时返回“真”,判断匹配与否时区分字符大小写;

    !~*:与指定正则表达式模式不匹配时返回“真”,判断匹配与否时不区分字符大小写;

    2、文件及目录匹配判断:

    -f, !-f:判断指定的路径是否为存在且为文件;

    -d, !-d:判断指定的路径是否为存在且为目录;

    -e, !-e:判断指定的路径是否存在,文件或目录均可;

    -x, !-x:判断指定路径的文件是否存在且可执行;

    - last 相当于Apache里的[L]标记,表示完成rewrite,呵呵这应该是最常用的
    - break 终止匹配, 不再匹配后面的规则
    - redirect 返回302临时重定向 地址栏会显示跳转后的地址
    - permanent 返回301永久重定向 地址栏会显示跳转后的地址

    nginx全局变量
    arg_PARAMETER    #这个变量包含GET请求中,如果有变量PARAMETER时的值。
    args                    #这个变量等于请求行中(GET请求)的参数,如:foo=123&bar=blahblah;
    binary_remote_addr #二进制的客户地址。
    body_bytes_sent    #响应时送出的body字节数数量。即使连接中断,这个数据也是精确的。
    content_length    #请求头中的Content-length字段。
    content_type      #请求头中的Content-Type字段。
    cookie_COOKIE    #cookie COOKIE变量的值
    document_root    #当前请求在root指令中指定的值。
    document_uri      #与uri相同。
    host                #请求主机头字段,否则为服务器名称。
    hostname          #Set to themachine’s hostname as returned by gethostname
    http_HEADER
    is_args              #如果有args参数,这个变量等于”?”,否则等于”",空值。
    http_user_agent    #客户端agent信息
    http_cookie          #客户端cookie信息
    limit_rate            #这个变量可以限制连接速率。
    query_string          #与args相同。
    request_body_file  #客户端请求主体信息的临时文件名。
    request_method    #客户端请求的动作,通常为GET或POST。
    remote_addr          #客户端的IP地址。
    remote_port          #客户端的端口。
    remote_user          #已经经过Auth Basic Module验证的用户名。
    request_completion #如果请求结束,设置为OK. 当请求未结束或如果该请求不是请求链串的最后一个时,为空(Empty)。
    request_method    #GET或POST
    request_filename  #当前请求的文件路径,由root或alias指令与URI请求生成。
    request_uri          #包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。不能修改。
    scheme                #HTTP方法(如http,https)。
    server_protocol      #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
    server_addr          #服务器地址,在完成一次系统调用后可以确定这个值。
    server_name        #服务器名称。
    server_port          #请求到达服务器的端口号。

    下面是可以用作if判断的全局变量

    • $args : #这个变量等于请求行中的参数,同$query_string
    • $content_length : 请求头中的Content-length字段。
    • $content_type : 请求头中的Content-Type字段。
    • $document_root : 当前请求在root指令中指定的值。
    • $host : 请求主机头字段,否则为服务器名称。
    • $http_user_agent : 客户端agent信息
    • $http_cookie : 客户端cookie信息
    • $limit_rate : 这个变量可以限制连接速率。
    • $request_method : 客户端请求的动作,通常为GET或POST。
    • $remote_addr : 客户端的IP地址。
    • $remote_port : 客户端的端口。
    • $remote_user : 已经经过Auth Basic Module验证的用户名。
    • $request_filename : 当前请求的文件路径,由root或alias指令与URI请求生成。
    • $scheme : HTTP方法(如http,https)。
    • $server_protocol : 请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
    • $server_addr : 服务器地址,在完成一次系统调用后可以确定这个值。
    • $server_name : 服务器名称。
    • $server_port : 请求到达服务器的端口号。
    • $request_uri : 包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
    • $uri : 不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
    • $document_uri : 与$uri相同。


    七.Apache和Nginx规则的对应关系
    Apache的RewriteCond对应Nginx的if
    Apache的RewriteRule对应Nginx的rewrite
    Apache的[R]对应Nginx的redirect
    Apache的[P]对应Nginx的last
    Apache的[R,L]对应Nginx的redirect
    Apache的[P,L]对应Nginx的last
    Apache的[PT,L]对应Nginx的last

  • 相关阅读:
    【转】漫谈linux文件IO--io流程讲的很清楚
    iostat命令
    【转】ATA Secure Erase
    同步IO和异步IO
    fio2.1.10--README
    【转】地址空间、内核空间、IO地址空间
    博客收藏--sailing的博客
    Cosmos OpenSSD架构分析--HOST interface(未完)
    nginx 过滤zip 类型的文件
    freeswitch GUI界面(portal)
  • 原文地址:https://www.cnblogs.com/ajaxa/p/9723530.html
Copyright © 2020-2023  润新知