Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

NGINX: How to correctly use an IF statement to include a proxy_pass

I am trying to use an IF statement in the location context inside my nginx.conf to add a proxy_pass element if the application is started up as being in local mode

events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    upstream myui.local {
        server 172.17.0.1:4200;
    }
    server {
        listen 80;
        listen [::]:80;
        server_name localhost;
        location / {
            set $env "local";
            root /usr/share/nginx/html;
            index index.html index.htm;
            resolver 127.0.0.1 valid=15s;
            if($env = 'local') {
                proxy_pass http://myui.local;
            }
        }
    }
}

But the if statement is causing this error

2021/01/28 12:10:56 [emerg] 11#11: unknown directive "if($env" in /etc/nginx/nginx.conf:19
nginx: [emerg] unknown directive "if($env" in /etc/nginx/nginx.conf:19

And I don't know enough about nginx yet to work out why. Any ideas SO?

question from:https://stackoverflow.com/questions/65936953/nginx-how-to-correctly-use-an-if-statement-to-include-a-proxy-pass

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...