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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 禁止某些終端訪問 不同的業務應用場景,會有完全不同的非法終端控制策略,常見的限制策略有終端IP、訪問域名端口,這些可以通過防火墻等很多成熟手段完成。可也有一些特定限制策略,例如特定cookie、url、location,甚至請求body包含有特殊內容,這種情況下普通防火墻就比較難限制。 Nginx的是HTTP 7層協議的實現著,相對普通防火墻從通訊協議有自己的弱勢,同等的配置下的性能表現絕對遠不如防火墻,但它的優勢勝在價格便宜、調整方便,還可以完成HTTP協議上一些更具體的控制策略,與iptable的聯合使用,讓Nginx玩出更多花樣。 ### 列舉幾個限制策略來源 - IP地址 - 域名、端口 - Cookie特定標識 - location - body中特定標識 > 示例配置(allow、deny) ~~~ location / { deny 192.168.1.1; allow 192.168.1.0/24; allow 10.1.1.0/16; allow 2001:0db8::/32; deny all; } ~~~ 這些規則都是按照順序解析執行直到某一條匹配成功。在這里示例中,10.1.1.0/16 and 192.168.1.0/24都是用來限制IPv4的,2001:0db8::/32的配置是用來限制IPv6。具體有關allow、deny配置,請參考[這里](http://nginx.org/en/docs/http/ngx_http_access_module.html)。 > 示例配置(geo) ~~~ Example: geo $country { default ZZ; proxy 192.168.100.0/24; 127.0.0.0/24 US; 127.0.0.1/32 RU; 10.1.0.0/16 RU; 192.168.1.0/24 UK; } if ($country == ZZ){ return 403; } ~~~ 使用geo,讓我們有更多的分之條件。注意:在Nginx的配置中,盡量少用或者不用if,因為"if is evil"。[點擊查看](http://wiki.nginx.org/IfIsEvil) 目前為止所有的控制,都是用Nginx模塊完成,執行效率、配置明確是它的優點。缺點也比較明顯,修改配置代價比較高(reload服務)。并且無法完成與第三方服務的對接功能交互(例如調用iptable)。 在Openresty里面,這些問題就都容易解決,還記得access_by_lua么?推薦一個第三方庫[lua-resty-iputils](https://github.com/hamishforbes/lua-resty-iputils)。 > 示例代碼: ~~~ init_by_lua ' local iputils = require("resty.iputils") iputils.enable_lrucache() local whitelist_ips = { "127.0.0.1", "10.10.10.0/24", "192.168.0.0/16", } -- WARNING: Global variable, recommend this is cached at the module level -- https://github.com/openresty/lua-nginx-module#data-sharing-within-an-nginx-worker whitelist = iputils.parse_cidrs(whitelist_ips) '; access_by_lua ' local iputils = require("resty.iputils") if not iputils.ip_in_cidrs(ngx.var.remote_addr, whitelist) then return ngx.exit(ngx.HTTP_FORBIDDEN) end '; ~~~ 以次類推,我們想要完成域名、Cookie、location、特定body的準入控制,甚至可以做到與本地iptable防火墻聯動。我們可以把IP規則存到數據庫中,這樣我們就再也不用reload nginx,在有規則變動的時候,刷新下nginx的緩存就行了。 思路打開,大家后面多嘗試各種玩法吧。
                  <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>

                              哎呀哎呀视频在线观看