# Nginx dies after a few minutes (unicorn)

**URL:** <https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762>\
**Category:** NGINX\
**Created:** [August 5, 2010, 4:57am UTC](https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762 "2010-08-05T04:57:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apollo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@apollo](https://www.ruby-forum.com/u/apollo)\
**Post date:** [August 5, 2010, 4:57am UTC](https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762/1 "2010-08-05T04:57:24Z")

</div>

I am running unicorn behind nginx to host Rails 3

Both nginx and unicorn run flawlessly when first started but nginx dies  
inexplicably about 5-10 minutes later. Unicorn, however, stays up and is  
still accessible through its own port.

Here is my nginx configuration pertaining to this application:

upstream unicorn {  
server unix:/tmp/.sock fail\_timeout=0;  
}

server {  
server\_name [example.com](http://example.com);  
root /www/example.com/current/public;

```
keepalive_timeout 5;

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    if (!-f $request_filename) {
        proxy_pass http://unicorn;
        break;
    }
}

```

}

I have nginx’s error\_log enabled with the debug flag but there are few  
clues in the error log file:

2010/08/04 19:34:59 [info] 20254#0: \*4 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:34:59 [info] 20254#0: \*5 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:35:17 [info] 20254#0: \*8 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:35:17 [info] 20254#0: \*9 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:35:18 [info] 20254#0: \*10 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:35:18 [info] 20254#0: \*11 client 98.173.61.21 closed  
keepalive connection  
2010/08/04 19:35:18 [info] 20254#0: \*12 client 98.173.61.21 closed  
keepalive connection

---

<div class="post-metadata">

**Author:** ![apollo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@apollo](https://www.ruby-forum.com/u/apollo)\
**Post date:** [August 5, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762/2 "2010-08-05T12:16:29Z")

</div>

On Thu, Aug 05, 2010 at 04:57:24AM +0200, Stanley Sh wrote:

> I am running unicorn behind nginx to host Rails 3
> 
> Both nginx and unicorn run flawlessly when first started but nginx dies  
> inexplicably about 5-10 minutes later. Unicorn, however, stays up and is  
> still accessible through its own port.

What do you mean by “dies” ?  
Are you able to download any static file from nginx ?

> ```
> }
> 
> ```
> 
> }

By the way, it’s better to use this configuration:

```
 location / {
     try_files $uri $uri/ @unicorn;
 }

 location @unicorn {
     proxy_pass http://unicorn;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $host;
     proxy_redirect off;
 }

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![apollo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@apollo](https://www.ruby-forum.com/u/apollo)\
**Post date:** [August 6, 2010, 8:51am UTC](https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762/3 "2010-08-06T08:51:13Z")

</div>

On Thu, Aug 05, 2010 at 11:48:39PM +0200, Stanley Sh wrote:

> Igor, the mistake was my own. Monit was the culprit, it was turning off  
> nginx because I had it misconfigured.
> 
> However, after changing the virtualhost conf to reflect your  
> suggestions, I now get the 403 forbidden error.

Try this:

```
 location / {

```

- 

```
   try_files $uri $uri/ @unicorn;

```

- 

```
   try_files $uri @unicorn;

```

}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![apollo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@apollo](https://www.ruby-forum.com/u/apollo)\
**Post date:** [August 5, 2010, 11:48pm UTC](https://www.ruby-forum.com/t/nginx-dies-after-a-few-minutes-unicorn/192762/4 "2010-08-05T23:48:39Z")

</div>

Igor, the mistake was my own. Monit was the culprit, it was turning off  
nginx because I had it misconfigured.

However, after changing the virtualhost conf to reflect your  
suggestions, I now get the 403 forbidden error.

PS: spasibo za pomesh
