国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

Nginx中IF、AND、OR語句用法實例

2024-08-30 12:21:48
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了Nginx中IF、AND、OR語句用法實例,本文講解的是Ningx中的邏輯判斷語句用法,需要的朋友可以參考下

在上一篇文章:《Nginx if語句加正則表達式實現字符串截斷》中, 我們介紹過了使用if來進行截斷字符串的用法, 這次我們來了解下if的邏輯用法:
什么是邏輯用法呢, 就程序中的and、or關系, 就叫做邏輯了.

NGINX支持if的 and 與 or 或者 && 與 || 嗎?

答案是No.
當你嘗試這樣配置, 重載nginx時, nginx會報出錯誤
復制代碼 代碼如下:
    location = /test/ {
        default_type text/html;
        set $b 0;
        if ( $remote_addr != '' && $http_x_forwarded_for != '' ){
            set $b '1';
        }
        echo $b;
    }
[root@test-vm ~]# /usr/local/nginx/sbin/nginx -t

nginx: [emerg] invalid condition "$remote_addr" in /usr/local/nginx/conf/nginx.conf:60
configuration file /usr/local/nginx/conf/nginx.conf test failed

那么我們應該怎樣來實現and 和or的邏輯關系呢?
復制代碼 代碼如下:
    location = /test_and/ {
        default_type text/html;
        set $a 0;
        set $b 0;
        if ( $remote_addr != '' ){
            set $a 1;
        }
        if ( $http_x_forwarded_for != '' ){
            set $a 1$a;
        }
        if ( $a = 11 ){
            set $b 1;
        }
        echo $b;
    }
    location = /test_or/ {
        default_type text/html;
        set $a 0;
        set $b 0;
        if ( $remote_addr != '' ){
            set $a 1;
        }
        if ( $http_x_forwarded_for != '' ){
            set $a 1;
        }
        if ( $a = 1 ){
            set $b 1;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金乡县| 新闻| 上饶县| 南开区| 乐至县| 麻江县| 宁明县| 汶川县| 河间市| 同心县| 林甸县| 锡林郭勒盟| 昆明市| 佛学| 郎溪县| 万宁市| 玉门市| 康马县| 榕江县| 无锡市| 龙泉市| 淮北市| 达日县| 鹤庆县| 乾安县| 长顺县| 达尔| 通山县| 图木舒克市| 竹溪县| 秦皇岛市| 柳河县| 饶河县| 宁德市| 宾川县| 聂拉木县| 文成县| 佛冈县| 德庆县| 札达县| 双牌县|