nginx初探(1)

(1)Nginx配置文件事实上是一个脚本语言,类似于perl和shell 

         1)set

         set是赋值语句,主要用于给modules里面定义的变量赋值,例如

         set $a "hello world";

         这样就是给某个模块里面变量为a的这个参数进行了赋值

         2)rewirte

         内部跳转指令

        rewrite ^ /bar

        3) 内部变量

        对于一个网址 http://localhost:8080/test?a=3&b=4

        $uri = /test

        $request_uri = /test?a=3&b=4

        $arg_a=3

        $args ="a=3&b=4"

        注意:参数名字会默认变成小写,如果想对参数进行html编解码,可以用模块 ngx_set_misc模块提供的指令set_unescape_uri

       4) 方向代理指令

       proxy_pass URL

       5)其他变量

        $request_method 请求的类型

        $cookie_XXX cookie值

        $content_length

        $content_type

       $document_root

       $document_uri

       $host

       $http_user_agent

       $http_cookie

       $limit_rate

       $request_body_file

       $request_method

       $remote_addr

      $remote_port

      $remote_user

     $request_filename

      $request_uri

      $query_string

     $scheme

      $server_protocol

      $server_addr

      $server_name

       $server_port

        6) if语句

       if (-d $request_filename){  //自动加目录

                  rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

        }

       if ($args !~ ^(url|auto)) {

     rewrite ^(.*)$ http://$server_name/?url=$uri$is_args$args break;

     }

     由于nginx加入了pcre库,所以nginx是支持正则表达式的rewrite的

Technorati 标签: nginx

posted on 2011-12-29 23:40  徐佳佳crest  阅读(206)  评论(0)    收藏  举报

导航