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:
http://forum.nginx.org/read.php?2,123451,123451#msg-123451

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
http://wiki.nginx.org/IfIsEvil.

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:
http://forum.nginx.org/read.php?2,123451,123616#msg-123616

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs