Welcome! Log In Create A New Profile

Advanced

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

Nuno Magalhães
September 03, 2009 06:28PM
> how heavy is your '/site01/file.php' script? (btw, I dont see any reference
> to it in your 502 log file)

The log's of site02. None of the sites is big or complex and none of
the examples i've used even accesses databases (although both sites
use a DB).

> I would imagine that the cause would be because nginx does not queue
> connections. And you have only a limited number of fastcgi processes (or how
> are u running your fastcgi?) Therefore when they are busy, and cannot accept
> connections, you will get a reset (i dont know how u're setting up your
> fastcgi, but!). The html without php gets cached very easily - therefore
> it's 200s all the way after any initial problems.

FastCGI runs as a daemon, i use the Debian php-cgi[1] package. It
spawns the master process plus 4 others. The start/stop script is the
one that comes with the package. This is in /etc/default/php-fastcgi:
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000

What's the time period for those requests? 1000 per second? Per child
simultaneously? I currently have two server{ }s included in
nginx.conf, and put my fast-cgi daemon running on 8888.

One handles 3 sites as /sitexx/ subfolders:

server {
server_name localhost;
listen 127.0.0.1:8080;
access_log /var/log/nginx/localhost.access.log vpt;
error_log /var/log/nginx/localhost.error.log;
charset utf-8;

location / {
root /var/www/nginx-default;
index index.php index.html;
}
location = /favicon.ico {
return 204;
}
error_page 404 /40x.html;
location = /40x.html {
root /var/www/nginx-default;
}
error_page 403 /403.html;
location = /403.html {
root /var/www/nginx-default;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
location ~ \.(php|html)$ {
fastcgi_pass localhost:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/nginx-default$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/nginx-default;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}

- One is a one-page form. No errors :)

- One is the one with a php menu (.php?menu=option then loads content
accordingly), uses sessions and form-validation, includes
session-related stuff and some http headers. 502 errors

- One is a simple site with php-menu.

After testing them all, this last site doesn't 502 on me despite
having a php-menu like the one that uses sessions...

I 'forked' one of the sites (the fourth) to another server{ } running
on a different port, that way it resembles more the production server
(which uses domains, not subdirectories of course):

server {
server_name localhost;
listen 127.0.0.1:8081;
access_log /var/log/nginx/reagentes.access.log vpt;
error_log /var/log/nginx/reagentes.error.log debug;
charset utf-8;

location / {
root /var/www/nginx-default/reagentes;
index index.html;
try_files $uri $uri/ $uri/index.html;
}
location = /favicon.ico {
return 204;
}
error_page 404 /40x.html;
location = /40x.html {
root /var/www/nginx-default/reagentes;
}
error_page 403 /403.html;
location = /403.html {
root /var/www/nginx-default/reagentes;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default/reagentes;
}
location ~ \.(php|html)$ {
fastcgi_pass localhost:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/nginx-default/reagentes$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/nginx-default/reagentes;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}

This fourth site (the site02 the log refers) at the moment is nothing
more than a simple page with some http headers, session stuff and a
login form with validation. I got it off the other site, and it 502s.
What's getting on my nerves is that i haven't changed these sites in
the last months, all i did was add a fourth site and only then i
noticed these issues. All the 3 sites were working great (or maybe i'm
going crazy), so i have... had no reason to doubt the code.

They had other options but i commented them out. They're very similar,
is there a way i can use something like $site='site02' and then use
location / {
root /var/www/nginx-default/$site;
instead? That would be nifty. (And i guess i could include other
locations from file as well, like the error handling or any common
stuff.)

I also haven't touched the production server (calling it "production"
is overrated, none of these sites are ready to the public, but i
neither changed the code nor the system), and it's churning along
fine. I'm even afraid to change anything and surely won't be upgrading
it anytime soon. It's running Debian Lenny (so stable) with a
2.6.26-2-686 kernel. nginx is 0.7.59 and PHP (only CGI; no CLI) is
5.2.6.

I do believe i need to somehow change my fastcgi settings, i'm just
not sure how or why. I'd like to avoid messing with the sites' code.
Any suggestions?

TIA,
Nuno Magalhães

[1] http://packages.debian.org/sid/php5-cgi

--
() ascii-rubanda kampajno - kontraŭ html-a retpoŝto
/\ ascii ribbon campaign - against html e-mail
Subject Author Posted

fastcgi causing 502 errors? [was: alternating 404 and 200]

Nuno Magalhães September 03, 2009 04:00PM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

Jeffrey 'jf' Lim September 03, 2009 04:10PM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

Nuno Magalhães September 03, 2009 06:28PM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

Jeffrey 'jf' Lim September 03, 2009 09:42PM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

Nuno Magalhães September 04, 2009 10:53AM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

vesperto September 07, 2009 10:34AM

Re: fastcgi causing 502 errors? [was: alternating 404 and 200]

vesperto September 08, 2009 06:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 314
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready