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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…