<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之旅 廣告
                # if 是邪惡的 當在location區塊中使用 if 指令的時候會有一些問題, 在某些情況下它并不按照你的預期運行而是做一些完全不同的事情. 而在另一些情況下他甚至會出現段錯誤. 一般來說避免使用 if 指令是個好主意. 在location區塊里if指令下唯一100%安全的指令應該只有: ##### return …; ##### rewrite … last; 除此以外的指令都可能導致不可預期的行為, 包括詭異的發出段錯誤信號(SIGSEGV). 要著重注意的是if的行為不是反復無常的, 給出兩個條件完全一致的請求, Nginx并不會出現一個正常工作而一個請求失敗的隨機情況, 在明晰的測試和理解下 if 是完全可用的. 盡管如此, 在這里還是建議使用其他指令. 總有一些情況你無法避免去使用 if 指令, 比如你需要測試一個變量, 而它沒有相應的配置指令. ~~~ if ($request_method = POST) { return 405; } if ($args ~ post=140){ rewrite ^ http://example.com/ permanent; } ~~~ #### 如何替換掉if 使用 try_files 如果他適合你的需求. 在其他的情況下使用 “return …” 或者 “rewrite … last”. 還有一些情況可能要把 if 移動到 server 區塊下(只有當其他的rewrite模塊指令也允許放在的地方才是安全的). 如下可以安全地改變用于處理請求的 location. ~~~ location / { error_page 418 = @other; recursive_error_pages on; if ($something) { return 418; } # some configuration ... } location @other { # some other configuration ... } ~~~ 在某些情況下使用嵌入腳本模塊(嵌入perl或者其他一些第三方模塊)處理這些腳本更佳. 例子 以下是一些例子用來解釋為什么if是邪惡的. 非專業人事指, 請勿模仿! ~~~ # 這里收集了一些出人意料的坑爹配置來展示 location 中的 if 指令是萬惡的 # 只有第二個 header 才會在響應中展示 # 這不是Bug, 只是他的處理流程如此 location /only-one-if { set $true 1; if ($true) { add_header X-First 1; } if ($true) { add_header X-Second 2; } return 204; } # 因為if, 請求會在未改變uri的情況下下發送到后臺的 '/' location /proxy-pass-uri { proxy_pass http://127.0.0.1:8080/; set $true 1; if ($true) { # nothing } } # 因為if, try_files 失效 location /if-try-files { try_files /file @fallback; set $true 1; if ($true) { # nothing } } # nginx 將會發出段錯誤信號(SIGSEGV) location /crash { set $true 1; if ($true) { # fastcgi_pass here fastcgi_pass 127.0.0.1:9000; } if ($true) { # no handler here } } # alias with captures isn't correcly inherited into implicit nested location created by if # alias with captures 不能正確的繼承到由if創建的隱式嵌入的location location ~* ^/if-and-alias/(?<file>.*) { alias /tmp/$file; set $true 1; if ($true) { # nothing } } ~~~ #### 為什么會這樣且到現在都沒修復這些問題? if 指令是 rewrite 模塊中的一部分, 是實時生效的指令.另一方面來說, nginx 配置大體上是陳述式的.在某些時候用戶出于特殊是需求的嘗試, 會在if里寫入一些非rewrite指令, 這直接導致了我們現處的情況. 大多數情況下他可以工作, 但是…看看上面.看起來唯一正確的修復方式是完全禁用if中的非rewrite指令. 但是這將破壞很多現有可用的配置, 所以還沒有修復. #### 如果你還是想知道該如何使用if 如果你看完了上面所有內容還是想使用 if: 請確認你確實理解了該怎么用它.一些比較基本的用法可以在[這里](http://agentzh.blogspot.jp/2011/03/how-nginx-location-if-works.html)找到. ##### 做適當的測試. 我已經警告過你了! > 文章選自:[http://xwsoul.com/posts/761](http://xwsoul.com/posts/761)TODO:這個文章后面需要自己翻譯,可能有版權問題:[https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/](https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/)
                  <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>

                              哎呀哎呀视频在线观看