Include in if

nginx version: nginx/0.8.49

I would like to serve static files by default, in the absence -
uwsgi_pass.
So I wrote this:

server {
listen 80;
server_name www1;
location / {
root /var/www/1/public;
if (!-f $request_filename) {
include /etc/nginx/params_uwsgi;
uwsgi_pass unix:/var/www/1.sock;
}
}
}

Unfortunately, I have:
Restarting nginx: [emerg]: “include” directive is not allowed here in
line 7.

would it not be able to do “include” inside “if” ?!
any advice ?

Posted at Nginx Forum:

Hello!

On Wed, Aug 25, 2010 at 07:09:09AM -0400, ddarko wrote:

root /var/www/1/public;
if (!-f $request_filename) {
  include /etc/nginx/params_uwsgi;
  uwsgi_pass unix:/var/www/1.sock;
}

}
}

root /path/to/server/root;

location / {
    try_files $uri @fallback;
}

location @fallback {
    include /path/toparams_uwsgi;
    uwsgi_pass ...;
}

Unfortunately, I have:
Restarting nginx: [emerg]: “include” directive is not allowed here in
line 7.

would it not be able to do “include” inside “if” ?!
any advice ?

Short answer: because “if” is ugly hack, see
If is Evil… when used in location context | NGINX.

Long answer: “include” isn’t something special per config file
syntax, and should be explicitly supported by every directive
which takes block as argument. In it’s turn “if” takes block as
argument and doesn’t explicitly support “include”. And nobody is
willing to dig into it due to already outlined reasons (see short
answer).

Maxim D.

super. exactly what I was looking for.
THX !

greetings to all fans of Nginx.

Posted at Nginx Forum: