0

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?

deadtoy
  • 43
  • 4

0 Answers0