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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江油市| 漳浦县| 盖州市| 泽普县| 开远市| 无锡市| 铁岭市| 和顺县| 肇庆市| 白城市| 沾化县| 金秀| 邵武市| 赣榆县| 凉城县| 建平县| 南开区| 瓦房店市| 庄浪县| 兴仁县| 科尔| 濮阳县| 常州市| 萨嘎县| 蕉岭县| 镇江市| 梁平县| 共和县| 桃园县| 许昌县| 德保县| 织金县| 卓尼县| 大港区| 藁城市| 咸丰县| 吉林省| 龙海市| 左贡县| 盖州市| 兴安盟|