# Include in if

**URL:** <https://www.ruby-forum.com/t/include-in-if/193843>\
**Category:** NGINX\
**Created:** [August 25, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/include-in-if/193843 "2010-08-25T13:09:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddarko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@ddarko](https://www.ruby-forum.com/u/ddarko)\
**Post date:** [August 25, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/include-in-if/193843/1 "2010-08-25T13:09:51Z")

</div>

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:

> **[include in if](https://forum.nginx.org/read.php?2,123451,123451#msg-123451)**
>
> 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\_file

---

<div class="post-metadata">

**Author:** ![ddarko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@ddarko](https://www.ruby-forum.com/u/ddarko)\
**Post date:** [August 25, 2010, 1:38pm UTC](https://www.ruby-forum.com/t/include-in-if/193843/2 "2010-08-25T13:38:33Z")

</div>

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  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](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.

---

<div class="post-metadata">

**Author:** ![ddarko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@ddarko](https://www.ruby-forum.com/u/ddarko)\
**Post date:** [August 25, 2010, 6:10pm UTC](https://www.ruby-forum.com/t/include-in-if/193843/3 "2010-08-25T18:10:50Z")

</div>

super. exactly what I was looking for.  
THX !

greetings to all fans of Nginx.

Posted at Nginx Forum:

> **[Re: include in if](https://forum.nginx.org/read.php?2,123451,123616#msg-123616)**
>
> 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\_file
