I’m on dreamhost since 2007, and about a year ago they moved me to a VPS… lots of nodes, etc… etc… no problem with that… the problem was that Apache was using lots of memory and 95% of the requests are to static files (images), so I changed from Apage to nginx but since that my sites were always down due to
502 bad gateway
- Open your php.ini
How to know the location? execute a phpinfo() and search for Loaded Configuration File. On DH, it’s at/home/FTPUSERNAME/.php-ini - search for max_execution_time and set it to 90 (probably was 30)
max_execution_time = 90
504 Gateway Time-out
Here’s how I solved my problem…
Add the following lines to /dh/nginx/servers/httpd-psXXXXXX/nginx.conf in http { section
proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; fastcgi_send_timeout 60s; fastcgi_read_timeout 60s;
and then restart nginx.
I also added some sh*ts to cron…
#tCGI BandAid on DH # Version 4, 10-28-2011 # By JuanJose Galvez (DH Tech Support) # Set this up as a cron job under root # I normally save this under /root/php_fastcgi.sh # * * * * * /bin/sh /root/php_fastcgi.sh; # - Added support for PHP 5.3 # - Removed lsof check # - Writing to log # - Remove while loops # - Added user name to log and fixed date -Tyler #USERS=`ls -la /home/ | grep -v root | awk {'print $3'} | sed '/^$/d'` USERS=`grep pragma /dh/nginx/servers/*/nginx.conf | awk {'print $3'} | sort | uniq` for user in $USERS do echo "User: $user" PHPCOUNT=`ps aux | grep '.p*.sock' | grep $user | wc -l` echo "PHP Processes: $PHPCOUNT" if [ "$PHPCOUNT" -lt 3 ] then DATE=`date` echo "$DATE: Only $PHPCOUNT PHP Processes for $user" >> /root/cron_log.txt pkill -9 -f .p*.sock -u $user /etc/init.d/nginx startphp PHPCOUNT=`ps aux | grep '.p*.sock' | grep $user | wc -l` fi done
crontab -l | { cat; echo "* * * * * /bin/sh ~/nginx_cron.sh"; } | crontab -
sudo /etc/init.d/nginx stop
pkill -u sadulttools
killall -9 php5.cgi
sudo /etc/init.d/nginx start
Usefull links
http://wiki.dreamhost.com/Nginx#Configuration_File_Locations
http://www.nginxtips.com/502-bad-gateway-using-nginx/
http://www.nginxtips.com/504-gateway-time-out-using-nginx/
http://serverfault.com/questions/121824/nginx-502-bad-gateway-fastcgi-not-listening-debian-5
http://serverfault.com/questions/178671/nginx-php-fpm-504-gateway-time-out-error-with-almost-zero-load-on-a-test-se