Trying to use nginx w/ drupal on dreamhost VPS - PHP/FastCGI crashes

Events happening in the community are now at Drupal community events on www.drupal.org.
reikiman's picture

I've been fairly happy w/ dreamhost and I like having their support team behind me. But - every time I try out nginx fastcgi/PHP crashes after several hours and the site goes down. I wonder if anybody here has seen this or has some ideas.

That is - yesterday I tried switching to nginx .. for a few hours it worked fine, and was faster than under apache. All was fine when I went to bed. This morning the site was down, and giving an "Bad Gateway" error page from nginx. Upon logging in to the server the fastcgi processes were not running and there was only the nginx master and worker processes.

Obviously if fastcgi was down, then nginx would be unable to contact PHP and unable to process the request and nginx would have no choice but to put up a "Bad Gateway" page.

One thing I'm curious about is why isn't fastcgi restarting if it crashes?

The nginx config being used was created by Dreamhost - so the other issue is, why does Dreamhost give me an nginx config that is so fragile?

The PHP portion is:-

            # PHP
            location ~* \.(php|php5|php4)($|/) {
                    fastcgi_param SERVER_PORT 80;
                    fastcgi_split_path_info ^(.+\.(?:php|php5|php4))(/.*)$;
                    if (!-e $document_root$fastcgi_script_name) {
                            return 404;
                    }
                    include /dh/nginx/etc/fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_pass unix:/home/robogeek5/.php.sock;
                    #pragma php_launch robogeek5
            }

Comments

hmmm... monitor fastcgi?

reikiman's picture

http://www.ruby-forum.com/topic/1058059 - describes the same problem and one of the commenters there says: Everybody has that problem with PHP. The solution is to monitor PHP with something (php-fpm, supervise, etc...)

Yes, dedicated servers have

brianmercer's picture

Yes, dedicated servers have moved to php-fpm now and it has proven to be very stable.

Unfortunately, php-fpm hasn't been very practical for shared hosts. The php-fpm devs have been working on an ondemand system to solve that problem. https://bugs.php.net/bug.php?id=52569 I have no experience with this new ondemand option and can't speak to its stability.

It really has nothing to do with the nginx config, and neither you or I are in a position to diagnose Dreamhost's problem with their php-fcgi implementation. Sorry.

FWIW I'm on a dreamhost VPS,

reikiman's picture

FWIW I'm on a dreamhost VPS, not dreamhost shared hosting. And, yeah, I'm looking at how to implement some kind of monitoring. But, yeah, I'm also stuck with the nginx config they gave me.

Well if you're on a VPS that

brianmercer's picture

Well if you're on a VPS that you control, then you can't blame Dreamhost. Switch to php-fpm. Dreamhost VPSes all have Debian? What OS and version are you running?

There's nothing terribly wrong with that nginx config, though there are several configs linked from the front page of the group that have been tweaked for security and efficiency and are tailored specifically for Drupal.

I beg to differ

perusio's picture

In fact you can run php-fpm without any need to restart it. That's hosgwash. You can even setup a backup pool. Depending on the resources that your VM can use, you can load balance on the FCGI upstream. Here's an example from my example config:

upstream phpcgi {
    ## If your version of Nginx doesn't have the fair load balancer:
    ## https://github.com/gnosek/nginx-upstream-fair comment out the
    ## following line.
    fair;
    server 127.0.0.1:9001;
    server 127.0.0.1:9002;
    ## Create a backend connection cache. Note that this requires
    ## Nginx version greater or equal to 1.1.4.
    ## Cf. http://nginx.org/en/CHANGES. Comment out the following
    ## line if that's not the case.
    keepalive 5;
}

Also TCP sockets are more reliable than UNIX Domain Sockets for high loads. There's no need to use PATH_INFO. Drupal doesn't use it at all. So you can simplify your config considerably. Although as Brian said it's not terribly wrong but there's room for improvement.

Just in case

perusio's picture

you're wanting a script to automatically restart php-fpm while you're tuning the parameters to get it stable. Here's a script I posted on github.

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: