include file with "if" statements

w_boba nginx-forum at forum.nginx.org
Wed May 18 15:35:48 UTC 2016


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 ?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,266986,266986#msg-266986



More information about the nginx mailing list