May 18, 2016 11:35AM
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 ? Why am I getting this error ?
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: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready