国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 论坛| 胶州市| 磐石市| 汽车| 时尚| 新沂市| 威远县| 明水县| 凤庆县| 南通市| 夏邑县| 东阳市| 中牟县| 泰安市| 永登县| 留坝县| 平乐县| 芦溪县| 乌海市| 江北区| 芜湖县| 拉萨市| 嵊州市| 繁昌县| 乌鲁木齐县| 蓬莱市| 巴东县| 宁夏| 新源县| 东港市| 古丈县| 谢通门县| 新乐市| 育儿| 北碚区| 禄劝| 中牟县| 临武县| 金川县| 晴隆县| 普兰县|