<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### HttpRewrite模塊 This module makes it possible to change URI using regular expressions, and to redirect and select configuration depending on variables. 該模塊允許使用正則表達式改變URI,并且根據變量來轉向以及選擇配置。 If the directives of this module are given at the server level, then they are carried out before the location of the request is determined. If in that selected location there are further rewrite directives, then they also are carried out. If the URI changed as a result of the execution of directives inside location, then location is again determined for the new URI. 如果在server級別設置該選項,那么他們將在location之前生效。如果在location還有更進一步的重寫規則,location部分的規則依然會被執行。如果這個URI重寫是因為location部分的規則造成的,那么location部分會再次被執行作為新的URI。 This cycle can be repeated up to 10 times, after which Nginx returns a 500 error. 這個循環會執行10次,然后Nginx會返回一個500錯誤。 ### Directives - [#break break] - [#if if] - [#return return] - [#rewrite rewrite] - [#set set] - [#uninitialized_variable_warn uninitialized_variable_warn] ### break **語法:***break* **默認值:***none* **作用域:***server, location, if* Completes the current set of rules. 作用是完成當前的規則列 示例: ~~~ if ($slow) { : limit_rate 10k; : break; } ~~~ ### if **語法:***if (condition) { ... }* **默認:***none* **作用域:***server, location* Checks the truth of a condition. If the condition evaluates to true, then the code indicated in the curly braces is carried out and the request is processed in accordance with the configuration within the following block. Configuration inside directive if is inherited from the previous level. They can be assigned as the condition: - the name of variable; false values are: empty string "", or any string starting with "0"; - the comparison of variable with the line with using the `=` and `!=` operators; - pattern matching with regular expressions using the symbols `~*` and `~`: - `~` is case-sensitive match; - '~'符合,但是大小寫敏感 - `~*` specifies a case-insensitive match (firefox matches FireFox) - ~*大小寫不敏感的符合(firefox符合FireFox) - `!~ and !~*` mean the opposite, "doesn't match" - !~和!~*代表相反,“不符合” - checking for the existence of a file using the `-f and !-f` operators;使用-f以及!-f檢測一個文件是否存在 - checking existence of a directory using the `-d and !-d` operators;使用-d以及!-d檢測一個目錄是否存在 - checking existence of a file, directory or symbolic link using the `-e and !-e` operators;使用-e以及!-e檢測是否存在一個文件,一個目錄或者一個符號鏈接。 - checking whether a file is executable using the `-x and !-x` operators.使用-x以及!-x檢測一個文件是否可執行 Parts of the regular expressions can be in parentheses, whose value can then later be accessed in the `$1 to >$9` variables. Examples of use: ~~~ if ($http_user_agent ~ MSIE) { : rewrite ^(.*)$ /msie/$1 break; } if ($http_cookie ~* "id=([^;] +)(?:;|$)" ) { : set $id $1; } if ($request_method = POST ) { : return 405; } if (!-f $request_filename) { : break; : proxy_pass http://127.0.0.1; } if ($slow) { : limit_rate 10k; } if ($invalid_referer) { : return 403; } ~~~ The value of the built-in variable `$invalid_referer` is given by the directive valid_referers. ### return **語法:***return code* **默認值:***none* **作用域:***server, location, if* This directive concludes execution of the rules and returns the status code indicated to client. It is possible to use the following values: 204, 400, 402-406, 408, 410, 411, 413, 416 and 500-504. Furthermore, nonstandard code 444 closes the connection without sending any headers. 這個指令根據規則的執行情況,返回一個狀態值給客戶端。可使用值包括:204,400,402-406,408,410,411,413,416以及500-504。也可以發送非標準的444代碼-未發送任何頭信息下結束連接。 ### rewrite **語法:***rewrite regex replacement flag* **默認:***none* **作用域:***server, location, if* This directive changes URI in accordance with the regular expression and the replacement string. Directives are carried out in order of appearance in the configuration file. 這個指令根據表達式來更改URI,或者修改字符串。指令根據配置文件中的順序來執行。 Be aware that the rewrite regex only matches the relative path instead of the absolute URL. If you want to match the hostname, you should use an if condition, like so: 注意重寫表達式只對相對路徑有效。如果你想配對主機名,你應該使用if語句,如下: ~~~ if ($host ~* www\.(.*)) { : set $host_without_www $1; : rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo' } ~~~ Flags make it possible to end the execution of rewrite directives. If the replacement string begins with `http://` then the client will be redirected, and any further rewrite directives are terminated. Flags can be any of the following: - last - completes processing of rewrite directives, after which searches for corresponding URI and location - break - completes processing of rewrite directives - redirect - returns temporary redirect with code 302; it is used if the substituting line begins with `http://` - permanent - returns permanent redirect with code 301 Note that if an redirect is relative (has no host part), then when redirecting Nginx uses the "Host" header if the header match name of server_name directive or the first name of `server_name` directive, if the header does not match or is absent. If no `server_name` is set, then the local hostname is used. If you want Nginx to always use the "Host" header, you can use a wildcard "*" `server_name` (but see the restrictions on doing so).Example: ~~~ rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last; return 403; ~~~ But if we place these directives in location /download/, then it is necessary to replace flag "last" by "break", otherwise nginx will hit the 10 cycle limit and return error 500: ~~~ location /download/ { : rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; : rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break; : return 403; } ~~~ If in the line of replacement arguments are indicated, then the rest of the request arguments are appended to them. To avoid having them appended, place a question mark as the last character: ~~~ : rewrite ^/users/(.*)$ /show?user=$1? last; ~~~ 注: 對花括號( { 和 } )來說, 他們既能用在重定向的正則表達式里,也是用在配置文件里分割代碼塊, 為了避免沖突, 正則表達式里帶花括號的話,應該用雙引號(或者單引號)包圍。比如,要將類似以下的url ~~~ /photos/123456 ~~~ 重定向到: ~~~ /path/to/photos/12/1234/123456.png ~~~ 可以用以下方法 (注意雙引號): ~~~ rewrite "/photos/([0-9] {2})([0-9] {2})([0-9] {2})" /path/to/photos/$1/$1$2/$1$2$3.png; ~~~ ### set **syntax:***set variable value* **default:***none* **context:***server, location, if* Directive establishes value for the variable indicated. As the value it is possible to use a text, variables and their combination. ### uninitialized_variable_warn **syntax:***uninitialized_variable_warn on|off* **default:***uninitialized_variable_warn on* **context:***http, server, location, if* Enables or disables logging of warnings about noninitialized variables. Internally, the rewrite directives are compiled at the time the configuration file is loaded into internal codes, usable during the request by the interpreter. This interpreter is a simple stack virtual machine. For example, the directive: ~~~ location /download/ { : if ($forbidden) { : return 403; : } : if ($slow) { : limit_rate 10k; : } : rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; } ~~~ will be compiled into this sequence: ~~~ : variable $forbidden : checking to zero : recovery 403 : completion of entire code : variable $slow : checking to zero : checkings of regular expression : copying "/" : copying $1 : copying "/mp3/" : copying $2 : copying "..mpe" : completion of regular expression : completion of entire sequence ~~~ Note that there is no code for directive limit_rate, since it does not refer to module ngx_http_rewrite_module. The "if" block exists in the same part of the configuration as the "location" directive. If $slow is true, then what's inside the "if" block is evaluated, and in this configuration limit_rate it is equal to 10k. Directive: ~~~ : rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; ~~~ It is possible to reduce the sequence, if in the regular expression we include the first slash inside the parentheses: ~~~ : rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; ~~~ then the sequence will appear like this: ~~~ : checking regular expression : copying $1 : copying "/mp3/" : copying $2 : copying "..mpe" : completion of regular expression : completion of entire code ~~~ ### References [Original Documentation](http://sysoev.ru/nginx/docs/http/ngx_http_rewrite_module.html "http://sysoev.ru/nginx/docs/http/ngx_http_rewrite_module.html")
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看