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

                ## 一、域名重定向 ``` if ($host ~* !^www.) { return 301 https://www.替換你的域名.com$request_uri; break; } ``` ## 二、UA防盜鏈 >[danger] 對于個人或小型網站來說,我不希望國外蜘蛛來訪問我的網站,特別是個別垃圾蜘蛛,它們訪問特別頻繁。這些垃圾流量多了之后,嚴重浪費服務器的帶寬和資源。通過判斷user agent,在nginx中禁用這些蜘蛛可以節省一些流量,也可以防止一些惡意的訪問。 ``` if ($http_user_agent ~* (Scrapy|Curl|HttpClient|Hacker|Creaker)) { return 403; } ``` ## 三、Referer防盜鏈 >[danger] **背景說明**:為了避免他人獲取服務器資源,只能讓本服務器能正常訪問服務器資源,使用refer做防止其他網站或直接獲取服務器資源,在nginx中配置如下: ``` location ~ /uploads/mail/201 { valid_referers blocked www.pinlucky.com www.pinlucky.cn; #valid_referers blocked $server_name; if ($invalid_referer) { rewrite ^/ /static/img/openRedBG.png; return 403; } #rewrite ^/ /static/img/openRedBG.png; } ``` ## 四、IP黑(白)名單 >[success] IP白名單 ``` allow 1.1.1.1; allow 1.1.1.2; deny 1.1.2.0/24; deny all; ``` >[success] IP黑名單 ``` deny 1.1.1.2; ``` ## 五、限速管理 ``` limit_conn perip 5; limit_rate 20k; ``` >[success] #上面這兩個limit的意思是:單個IP最大允許5個連接,單個連接帶寬為20K,若下載器一次可以發起5個請求(5個連接數),那么這個下載器最大下載速度為100K; ## 六、CC防攻擊 > https://www.centos.bz/2012/12/openresty-nginx-block-cc-attack-deploy/ ## 七、URL重寫 `rewrite ^(.*)$ /index.php?s=$1 last;` > PHP后綴改為html后綴(未測試) `rewrite ^(.*)\.php(.*)$ /$1\.html$2 last;` ## 八、過濾請求 ``` if ($request_method ~* GET|get) { rewrite ^(.*)$ /notice last; } ``` ## 九、頭部操作 > 添加響應頭部,這樣在瀏覽器的`Response Headers`就能看到客戶端的IP了,注意放到location里面,還可能被其他location覆蓋導致獲取不到。 ```nginx add_header yourip $remote_addr; ``` > 添加請求頭: ## 十、接收自定義頭部 比如我們自定義header為X-Real-IP,通過nginx獲取該header時需要這樣:$http\_x\_real\_ip; (一律采用小寫,而且前面多了個http\_) ``` curl http://127.0.0.1/nginx -H "A-B-C:a-B-c" -v 127.0.0.1 - a-B-c ``` ``` location /nginx { default_type text/html; return 200 '$remote_addr - $http_a_b_c'; } if ( $http_a_b_c != "abcdef00" ) { return 403 '訪問被禁止,訪問該請求需要特定的頭部'; } ```
                  <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>

                              哎呀哎呀视频在线观看