Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Jan 06, 2010 7:11 am 
Offline
Senior Member
User avatar

Joined: Tue Dec 01, 2009 10:31 pm
Posts: 57
Hi Linoders,

I'm a relative newbie to this VPS world, and jumped in with nginx 07.62 for my wordpress blog.

Unfortunately the fastcgi process is unstable, I find that it goes down every other day. The symptom's of such a crash are nginx 502 errors, both when I attempt to load the /wp-admin page, and on redirect after leaving a blog comment.

To fix the fault, it requires me to reboot or run a
Quote:
/etc/init.d/init-php restart
.

From this afternoon's crash, Nginx's error.log shows the following
Quote:
2010/01/06 14:14:23 [error] 2373#0: *30147 connect() failed (111: Connection refused) while connecting to upstream, client: 174.37.205.87, server: www.mydomain.com, request: "GET /feed/atom/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:14:47 [error] 2373#0: *30149 connect() failed (111: Connection refused) while connecting to upstream, client: 87.250.254.241, server: www.mydomain.com, request: "GET /forum/index.php?topic=9413.msg49196 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:14:55 [error] 2373#0: *30151 connect() failed (111: Connection refused) while connecting to upstream, client: 134.159.131.34, server: www.mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:15:04 [error] 2373#0: *30153 connect() failed (111: Connection refused) while connecting to upstream, client: 66.249.68.146, server: www.mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:15:04 [error] 2373#0: *30156 connect() failed (111: Connection refused) while connecting to upstream, client: 220.253.177.77, server: www.mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:15:11 [error] 2373#0: *30159 connect() failed (111: Connection refused) while connecting to upstream, client: 209.85.238.16, server: www.mydomain.com, request: "GET /feeds/posts/default HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:15:14 [error] 2373#0: *30161 connect() failed (111: Connection refused) while connecting to upstream, client: 134.159.131.34, server: www.mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:16:18 [error] 2619#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 134.159.131.34, server: www.mydomain.com, request: "GET /forum/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:16:19 [error] 2622#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 216.18.20.8, server: www.mydomain.com, request: "GET /feed/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com"
2010/01/06 14:17:45 [error] 2380#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 218.185.92.146, server: www.mydomain.com, request: "GET /the-start-of-the-melbourne-rebellion/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com", referrer: "http://www.google.com/search?q=Harold+MItchell+Melbourne+rebels&rls=com.microsoft:en-au:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7ADBR"


I've tried a few different approaches to run fastcgi, namely libfcgi0
, spawn-cgi, /usr/bin/php-cgi -b 127.0.0.1:9000, and now I'm considering PHP-FPM.

Does this sound like a reasonable strategy? I'm at the point where I might give up on nginx and just install apache2! I'd really rather not though, nginx absolutely flies when it's running..

I'd really appreciate any advice on what to check, or any alternatives I haven't yet found.

Cheers,
Moses.


Top
   
 Post subject:
PostPosted: Wed Jan 06, 2010 10:12 am 
Offline
Senior Member

Joined: Wed Jan 21, 2009 7:13 pm
Posts: 126
Location: Portugal
Hi,

i was in the same boat as you a few month ago, and switch to nginx proxy to apache, instead of fastcgi.

You just need to slow down apache and turn off keep alive:

<IfModule mpm_prefork_module>
StartServers 3
MinSpareServers 2
MaxSpareServers 2
MaxClients 25
MaxRequestsPerChild 1000
</IfModule>

For me this is the most stable and functional configuration I can have without loosing htaccess (I'm lazy to switch to nginx rules).

I only proxy php requests to apache. All other non script files (txt,, gif, png, etc) are served directly by nginx.


Top
   
 Post subject:
PostPosted: Wed Jan 06, 2010 10:55 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Where did you get that init-php script? What does it do?

Does your script set the PHP_FCGI_MAX_REQUESTS environment variable? Some versions of PHP will hang after a certain number of requests are served, so the environment variable above tells it to restart automatically before that happens. Try a value of 500 or less.

Examples:

http://redmine.lighttpd.net/projects/li ... iptsUbuntu
(This is for spawn-fcgi)

http://drupal.org/node/110224
(Without spawn-fcgi)

I personally prefer spawn-fcgi. Newer versions of it can even spawn multiple processes, each with their own children, listening on the same port. If one process hangs, others will keep working. Try that too. But you can't use an opcode cacher (APC, XCache) with multiple processes unless you want to waste a bit of RAM.


Top
   
 Post subject:
PostPosted: Wed Jan 06, 2010 12:29 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Resorting to Apache is unnecessary. It's not impossible to get stable fastcgi with nginx, and I've had no such troubles with Lighttpd either.


Top
   
PostPosted: Wed Jan 06, 2010 1:29 pm 
Offline
Newbie

Joined: Sat Dec 19, 2009 11:30 am
Posts: 3
Moses wrote:
spawn-cgi


spawn-cgi isn't perfect. I've heard many people complaining about it. PHP-FPM is any day better than spawn-cgi. If you're in the dark, follow this link: http://php-fpm.org/ :)


Top
   
 Post subject:
PostPosted: Thu Jan 07, 2010 5:55 am 
Offline
Senior Member
User avatar

Joined: Tue Dec 01, 2009 10:31 pm
Posts: 57
Could it be a config issue with the way I'm currently set up? Here's my config files in case there's anything obvious..

/usr/local/nginx/sites-available/default
Quote:
server {
listen 80;
server_name localhost;

location / {
root html;
index index.php index.html index.htm;
}

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}


/usr/local/nginx/sites-enabled/mydomain.com
Quote:
server {
listen 80;
server_name mydomain.com;
rewrite ^/(.*) http://www.mydomain.com/$1 permanent;
}

server {
listen 80;
server_name www.mydomain.com;
access_log /home/public_html/mydomain.com/log/access.log;
error_log /home/public_html/mydomain.com/log/error.log;

location / {
root /home/public_html/mydomain.com/public/;
index index.php index.html;
# Wordpress WP Super Cache plugin and permalinks.
include /usr/local/nginx/conf/wordpress_params.super_cache;

}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public/$fastcgi_script_name;
}


location ^~ /munin {
root /home/public_html/mydomain.com/public;
auth_basic "Restricted";
auth_basic_user_file /usr/local/nginx/.htpasswd;
}


}


/etc/init.d/php-fastcgi-new
Quote:
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
echo -n "Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop() {
echo -n "Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac


/usr/local/nginx/conf/fastcgi_params
Quote:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;


/usr/local/nginx/conf/nginx.conf
Quote:
user www-data www-data;
worker_processes 4;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 5;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

include /usr/local/nginx/sites-enabled/*;
}


Top
   
 Post subject:
PostPosted: Thu Jan 07, 2010 11:41 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Don't see anything obvious, other than the fact that
Code:
fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public/$fastcgi_script_name;

could be
Code:
fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public$fastcgi_script_name;

($fastcgi_script_name already comes with a leading slash)

But that shouldn't be causing the problem.

A few suggestions (not solutions):

Do you have logging enabled in your php.ini? Is there a particular request or error that always occurs just before PHP goes belly up? That could help track down the problem.

Did you install PHP from your distro's repository (apt, yum) or did you compile it yourself? Try reinstalling, e.g. apt-get install --reinstall php5-common php5-cgi

Does your FastCGI process just die, or does it stay alive but hang?

While you're troubleshooting this, here's a band-aid: write up a quick script that runs from crontab every minute, which checks if PHP is alive, and restarts PHP if not. If PHP just dies, ps -C php5-cgi -o cmd= should be enough to tell the difference. (No result if PHP is dead.) I used to do something like this back when lighttpd used to have hideous memory leaks 8)


Top
   
 Post subject:
PostPosted: Mon Jan 18, 2010 2:54 am 
Offline
Senior Newbie

Joined: Wed Dec 16, 2009 4:57 am
Posts: 7
Location: Fort Worth, TX
Moses,

Love your site. I've been following it ever since you posted about nginx/wordpress in December. Wordpress and your forum is always up and fast here in Texas.

Are you having problems keeping nginx going? I ran in to similar issues but worked them out last summer. Let me know if you are and I'll look up what I did. (I have to make notes, less things to permanently forget)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group