# Nginx on windows keeps hanging

**URL:** <https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850>\
**Category:** NGINX\
**Created:** [May 18, 2012, 7:36am UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850 "2012-05-18T07:36:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 18, 2012, 7:36am UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/1 "2012-05-18T07:36:26Z")

</div>

Hello,

I run my websites using linux, but for my current situation, I test my  
sites on my windows 7 64bit. I have setup nginx with php and mysql and  
everything works fine. But depending on how many requests get done in  
short period of time nginx keep hanging and I have to restart it.  
Hopefully someone knows what’s wrong with it.

My machine is Intel Quad Core + 4GB RAM + windows7 ultimate 64

This is my nginx conf:

worker\_processes 1;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
sendfile off;
keepalive_timeout 0;

server

```

{  
listen 3334;  
server\_name localhost;  
root E:/emergency/HTML/;

```
    location / {
        autoindex on;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}

My error log is filled with this:  
2012/05/18 09:29:16 [error] 3028#3052: \*504 upstream timed out (10060: A  
connection attempt failed because the connected party did not properly  
respond after a period of time, or established connection failed because  
connected host has failed to respond) while connecting to upstream,  
client: 127.0.0.1, server: localhost, request: “GET  
/index.php?action=home HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”,  
host: “localhost:3334”, referrer: “[http://localhost:3334/index.php](http://localhost:3334/index.php)”

Thanks for your time.  
(keepalive\_timeout was 200, then I tried 0, but still same result)

Posted at Nginx Forum:

> **[nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226613#msg-226613)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 18, 2012, 1:33pm UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/2 "2012-05-18T13:33:19Z")

</div>

You need to make a pool for fastcgi, see the loadbalance example

> **[Simple Load Balancing | NGINX](https://www.nginx.com/resources/wiki/start/topics/examples/loadbalanceexample/)**
>
> An example NGINX configuration that performs simple load balancing.

This solution is the same for any OS suffering from upstream timeouts.  
With a pool of 4 you can easily handle 1000 requests/sec, and yes even  
with nginx win32.

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226627#msg-226627)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 19, 2012, 6:13am UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/3 "2012-05-19T06:13:54Z")

</div>

Thanks for your post.

I did the following changes, but I’m still getting this error. Note that  
it is a local environment and I’m barely having 10 requests per second.  
Probably I didn’t get your point and circling around myself. I created 4  
more server blocks listening for 8000 to 8003 ports. I tried it without  
them and I couldn’t open any page so I tried this one:

http {  
include mime.types;  
default\_type application/octet-stream;

```
sendfile off;

keepalive_timeout 0;

```

upstream myproject {  
server 127.0.0.1:8000 weight=3;  
server 127.0.0.1:8001;  
server 127.0.0.1:8002;  
server 127.0.0.1:8003;  
}

```
server

```

{  
listen 3334;

```
    server_name localhost;
    root E:/emergency/HTML/;

    location / {
        autoindex on;
        proxy_pass http://myproject;
    }

}

server

```

{  
listen 8000;

```
    server_name localhost;
    root E:/emergency/HTML/;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}  
server  
{  
listen 8001;

```
    server_name localhost;
    root E:/emergency/HTML/;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}  
server  
{  
listen 8002;

```
    server_name localhost;
    root E:/emergency/HTML/;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}  
server  
{  
listen 8003;

```
    server_name localhost;
    root E:/emergency/HTML/;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226652#msg-226652)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 19, 2012, 9:04pm UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/4 "2012-05-19T21:04:58Z")

</div>

I’m new to this, please bare with me…

I’m running my fastcgi script using this .bat file:

@ECHO OFF  
D:\environments\php\php-cgi -b 127.0.0.1:9000 -c  
D:\environments\php\php.ini  
ping 127.0.0.1 -n 1\>NUL  
echo .  
echo .  
echo .  
EXIT

So for my upstream, I modified it to: (duplicated that line 4 times.  
will that work?)  
@ECHO OFF  
D:\environments\php\php-cgi -b 127.0.0.1:8004 -c  
D:\environments\php\php.ini  
D:\environments\php\php-cgi -b 127.0.0.1:8005 -c  
D:\environments\php\php.ini  
D:\environments\php\php-cgi -b 127.0.0.1:8006 -c  
D:\environments\php\php.ini  
D:\environments\php\php-cgi -b 127.0.0.1:8007 -c  
D:\environments\php\php.ini  
ping 127.0.0.1 -n 1\>NUL  
echo .  
echo .  
echo .  
EXIT

and this is my latest nginx.conf:

http {  
include mime.types;  
default\_type application/octet-stream;

```
sendfile off;

keepalive_timeout 0;

```

upstream myproject {  
server 127.0.0.1:8004;  
server 127.0.0.1:8005;  
server 127.0.0.1:8006;  
server 127.0.0.1:8007;  
}  
server  
{  
listen 3334;

```
    server_name localhost;
    root E:/emergency/HTML/;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    location ~ \.php$ {

        fastcgi_pass myproject;
        fastcgi_index index.php;
        fastcgi_param PHP_FCGI_MAX_REQUESTS 0;
        fastcgi_param PHP_FCGI_CHILDREN 100;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}

I get those error still, but I think they are less now. Still irritating  
though. I tried an ajax shoutbox script which fires requests every few  
seconds and opened up 4-5 browsers to see the reaction. I have upstream  
timeout errors. This time they haven’t paralyze nginx but the errors  
appear and ajax requests pend without any response. Lots of same error  
on port 8006.

2012/05/19 23:22:31 [error] 1092#3704: \*126 upstream timed out (10060: A  
connection attempt failed because the connected party did not properly  
respond after a period of time, or established connection failed because  
connected host has failed to respond) while connecting to upstream,  
client: 127.0.0.1, server: localhost, request: “GET  
/index.php?action=ajaxrequest HTTP/1.1”, upstream:  
“fastcgi://127.0.0.1:8006”, host: “localhost:3334”, referrer:  
“[http://localhost:3334/index.php](http://localhost:3334/index.php)”

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226655#msg-226655)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 19, 2012, 10:34pm UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/5 "2012-05-19T22:34:35Z")

</div>

Remove the PHP\_FCGI\_x lines and add “fastcgi\_ignore\_client\_abort on;”  
For the pool add for all of them “weight=1 fail\_timeout=5”

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226656#msg-226656)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 19, 2012, 12:50pm UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/6 "2012-05-19T12:50:33Z")

</div>

You have created a upstream but ain’t using it…

each line “fastcgi\_pass 127.0.0.1:9000;” must be changed to  
“fastcgi\_pass myproject;” then make sure the fpm processes are running  
for your pool.

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226653#msg-226653)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 20, 2012, 9:47am UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/7 "2012-05-20T09:47:26Z")

</div>

Without PHP\_FCGI\_x lines system got so much slow. I had to put them  
back. I noticed in the task bar there are always 1 or 2 php-cgi.exe  
processes while it must be 4. I splitted cgi.bat file into four  
individual files each handling one port. Now I have 4 php-cgi.exe  
processes and system is working even faster than before without any  
failures. Thanks! without you I couldn’t figure it out.

Since I’m holding task manager open, I see that sometimes cgi processes  
get closed and that causes upstream errors again. Why they are getting  
closed? is there a closure timeout for inactivity?

Also since we’re at it, how do I calculate my exact settings? number of  
cgi processes, max\_requests, children? (i’m planning to go with php-fpm  
on ubuntu)

Say in my busy hour, I have 150 users online. each one sending a request  
per second. Should I calculate every page request with their images and  
scripts, adding one request for each?

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226659#msg-226659)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...

---

<div class="post-metadata">

**Author:** ![asmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@asmith](https://www.ruby-forum.com/u/asmith)\
**Post date:** [May 20, 2012, 1:21pm UTC](https://www.ruby-forum.com/t/nginx-on-windows-keeps-hanging/219850/8 "2012-05-20T13:21:31Z")

</div>

A fpm pool of 4 for 1 worker is more then enough to have the same  
performance with win32 compared to linux, of-course linux supports more  
workers but you can get that on win32 too by loadbalancing multiple  
nginx installations using nginx itself in fpm frontend mode to multiple  
nginx backend nodes as, affinity managed, fpm pool.

Why php aborts depends on whats happening, have a look at php’s timeout  
settings and “ignore\_user\_abort = On”. Add a loop label in the batch so  
it restarts the cgi process. I haven’t yet had a fpm process terminate  
while the pool balances nicely to the amount of requests.

Use ab.exe(apache tool) to benchmark and tune things.

Posted at Nginx Forum:

> **[Re: nginx on windows keeps hanging](https://forum.nginx.org/read.php?2,226613,226660#msg-226660)**
>
> Hello, I run my websites using linux, but for my current situation, I test my sites on my windows 7 64bit. I have setup nginx with php and mysql and everything works fine. But depending on how many requests get done in short period of time nginx keep...
