Welcome! Log In Create A New Profile

Advanced

Re: include file with "if" statements

Maxim Dounin
May 18, 2016 02:30PM
Hello!

On Wed, May 18, 2016 at 11:35:48AM -0400, w_boba wrote:

> I have several different "templates" for location and most of templates have
> common part like this:
>
> ----------------------
> /etc/nginx/nginx.conf:
> http {
> include /etc/nginx/conf.d/*.conf;
> }
> ----------------------
> /etc/nginx/conf.d/config12345.conf:
> server {
> listen 12345;
> location / {
> some configuration;
> }
> location /special {
> include template12345.txt;
> }
> ----------------------
> /etc/nginx/template12345.txt:
> some configuration;
> if ($variable1 = "value1") { return 403; }
> if ($variable2 = "value2") { return 403; }
> if ($variable3 = "value3") { return 403; }
> some other configuration;
> ----------------------
>
> When I try to separate this "if" part into separate file like this:
> ----------------------
> /etc/nginx/conditions.txt
> if ( $variable1 = "value1" ) { return 403; }
> if ( $variable2 = "value2" ) { return 403; }
> if ( $variable3 = "value3" ) { return 403; }
> ----------------------
>
> and include it in the template like "include conditions.txt" instead of
> repeating this part in every template, I get error message:
> "nginx: [emerg] "if" directive is not allowed here in
> /etc/nginx/conditions.txt:1"
>
> So my question is: is there a limit to "include" directive depth ?

No.

> Why am I getting this error ?

Likely you've uninintentionally included conditions.txt into a
place where "if" directives cannot be used. In particular, this
can easily happen if you have various wildcard includes in your
configuration.

If unsure, please provide full minimal configuration which
triggers the error.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

include file with "if" statements

w_boba May 18, 2016 11:35AM

Re: include file with "if" statements

Maxim Dounin May 18, 2016 02:30PM

Re: include file with "if" statements

w_boba May 18, 2016 04:44PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 86
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready