3

Is it possible to define a global constant variable in the nginx config file?

I would like to define a constant for an IP Address, as it's used in multiple location blocks - see below:

        location / {
        satisfy all;
        allow 12.34.56.789;
        deny all;

        auth_basic "Restricted Remote";
        auth_basic_user_file /etc/nginx/.htpasswd_gpu;

        limit_req zone=login burst=5;
        proxy_pass *************;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }

Is there a way to define:

var my_ip_address = 12.34.56.789;

and then use that variable instead in the "allow" statement?

thanks!

vgoklani
  • 10,685
  • 16
  • 63
  • 101
  • 1
    No. But there are three things you could investigate. Inheritance (move the `allow` statement to the outer block), `allow all;` to override the setting in specific `location` blocks, or use `include` to place the common statements into a separate file and insert them where needed. – Richard Smith Aug 22 '20 at 06:48

0 Answers0