Nginx rewrite pseudo-static configuration parameters detailed description

  

nginx rewrite pseudo-static configuration parameters and use examples with regular usage instructions

regular expression matching, where:
* ~ for case-sensitive matching

  • * ~ * case-insensitive match
  • *! ~ and! ~ * are not case-sensitive and case-insensitive match does not match

    file And directory matching, where:
    * -f and !-f are used to determine whether a file exists

  • * -d and !-d are used to determine if a directory exists
  • * -e !! -e and used to determine whether there is a file or directory
  • * -x and -x is used to determine whether the file is executable

    flag marked with:
    * last Equivalent to the [L] tag in Apache, indicating completion of rewrite

  • * break terminates the match, no longer matches the following rules
  • * redirect returns 302 temporary redirected address bar will display after the jump address
  • * permanent return 301 permanent redirect address bar will show after the jump address

    Some of the available global variables, Use conditional judgment (to be completed)
    $args

  • $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
  • $ uri

    Example of combining QeePHP
    if (!-d $request_filename) {

  • rewrite ^/([azAZ]+)/([azAZ]+)/?(.*)$ /index.php? Namespace=user&controller=$1&action=$2&$3 last;
  • rewrite ^/([azAZ]+)/?$ /index.php?namespace=user&controller=$1 last;
  • break;

    multiple directory transformed into parameters abc.domian.com/sort/2 = & gt; abc.domian.com/index.php ?act=sort&name=abc&id=2
    if ($host ~* (.*)\\.domain\\.com) {

  • set $sub_name $1;
  • rewrite ^ /sort \\ /(\\ d +) \\ /$ /index.php?act=sort&cid=$sub_name&id=$1 last;?
  • }

    directory swapping /123456 /xxxx - & gt; /xxxx id = 123456
    rewrite ^ /(\\ d +) ///$ 2 id = $ 1 last;

    , for example, the following? (+)? Set nginx to redirect to /nginx-ie in the user's use of ie:
    if ($http_user_agent ~ MSIE) {

  • rewrite ^(.*)$ /nginx-ie/$1 break ;
  • }

    automatic directory & ldquo; /& rdquo;
    if (-d $ request_filename) {

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

    prohibit htaccess
    location ~ /\\ ht {
    <. li> deny all;

  • }

    prohibit multiple directories
    location ~ ^ /(cron | Templates/////////////multi-level directory and the like at the request .log.txt;
    location ~ ^ /data {

  • deny all;
  • }

    can not prevent a single directory prohibits .log.txt can request
    location /searchword/cron/{

  • deny all;
  • Copyright © Windows knowledge All Rights Reserved