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

首頁 > 網站 > Nginx > 正文

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

2024-08-30 12:26:45
字體:
來源:轉載
供稿:網友

在上一篇文章:《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;
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天水市| 大同县| 马公市| 新津县| 宁陵县| 内乡县| 东安县| 台湾省| 长汀县| 瓦房店市| 芒康县| 宜春市| 濮阳县| 宜昌市| 武冈市| 许昌县| 呼图壁县| 彭州市| 铅山县| 麻阳| 徐闻县| 马公市| 新昌县| 镇雄县| 绥芬河市| 湾仔区| 罗城| 西丰县| 电白县| 思茅市| 商水县| 小金县| 康马县| 佛冈县| 鄂伦春自治旗| 宣威市| 大庆市| 高邮市| 洛川县| 新田县| 长顺县|