include in if
Maxim Dounin
mdounin at mdounin.ru
Wed Aug 25 15:37:22 MSD 2010
Hello!
On Wed, Aug 25, 2010 at 07:09:09AM -0400, ddarko wrote:
> 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;
> }
> }
> }
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 Dounin
More information about the nginx
mailing list