<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## nginx 配置小結 > 原文:[https://www.cnblogs.com/CraryPrimitiveMan/p/6568032.html](https://www.cnblogs.com/CraryPrimitiveMan/p/6568032.html) -- 瘋狂原始人 前兩天區聽了一堂Nginx的課,然后翻了一下自己之前的Nginx的筆記,做了一個簡單的小結。 ## 全局變量 $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`相同 **假設請求為`http://www.qq.com:8080/a/b/c.php`,則 ** ``` $host:www.qq.com $server_port:8080 $request_uri:[http://www.qq.com:8080/a/b/c.php](http://www.qq.com:8080/a/b/c.php) $document_uri:/a/b/c.php $document_root:/var/www/html $request_filename:/var/www/html/a/b/c.php ``` ## 主機名(server\_name)匹配 從上到下的優先級為從高到低 1. 明確的`server_name`名稱,如`www.qq.com` 2. 前綴通配符,如`*.qq.com`或`. qq.com` 3. 后綴通配符,如`www.qq.*` 4. 正則表達式,如`~[a-z]+\.qq\.com` ## Location查找規則 從上到下的優先級為從高到低 1. 等號類型,精確匹配,如`location = / {}` 2. `^~`類型,前綴匹配,不支持正則,如`location ^~ /user {}` 3. `~`和`~*`類型,正則匹配,`~`區分大小寫,`~*`不區分大小寫,如`location ~ ^/user {}` 4. 常規字符串匹配類型,如`location / {}`或`location /user {}` ## Try\_files規則 try\_files $uri $uri/ /index.php 假設請求為`http://www.qq.com/test`,則`$uri`為`test` 1. 查找`/$root/test`文件 2. 查找`/$root/test/`目錄 3. 發起`/index.php`的內部“子請求” ## Rewrite規則 rewrite ^/images/(.\*).(png|jpg|gif)$ /images?name=$1.$4 last; 上面的`rewrite`規則會將文件名改寫到參數中 last : 相當于`Apache`的\[L\]標記,表示完成`rewrite` break : 停止執行當前虛擬主機的后續`rewrite`指令集 redirect : 返回302臨時重定向,地址欄會顯示跳轉后的地址 permanent : 返回301永久重定向,地址欄會顯示跳轉后的地址 ## 負載均衡 例子如下 ``` upstream backend1 { server backend1.qq.com weight=5; server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; server unix:/tmp/backend3 backup; } upstream backend2 { ip_hash; server backend1.qq.com; server backend2.qq.com; server backend3.qq.com down; server backend4.qq.com; } server { location / { proxy_pass http://backend1; } location /api { proxy_pass http://backend2; } } ``` ## 查看一個實例 下面是一個`laravel`框架`Nginx`配置的例子,聽過這堂課終于了解了下面的原理。 ~~~ server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; # 設定網站根目錄 root /var/www/laravel/public; # 網站默認首頁 index index.php index.html index.htm; # 服務器名稱,server_domain_or_IP 請替換為自己設置的名稱或者 IP 地址 server_name server_domain_or_IP; # 修改為 Laravel 轉發規則,否則PHP無法獲取$_GET信息,提示404錯誤 location / { try_files $uri $uri/ /index.php?$query_string; } # PHP 支持 location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ~~~ 我們主要關注兩個`location`,假設地址是`http://www.qq.com/user/info`,會匹配到如下`location` ~~~ location / { try_files $uri $uri/ /index.php?$query_string; } ~~~ 由于`$uri`和`$uri/`是不存在的,所以會走`/index.php?$query_string`,這時候會發起一個內部“子請求”,“子請求”會重新匹配`location`,然后匹配到如下`location` ~~~ location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ~~~ 這樣請求就會發送到`fastcgi`去做處理。
                  <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>

                              哎呀哎呀视频在线观看