Dreamhost, nginx, 502 Bad Gateway and 504 Gateway Time-out

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

  1. 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
  2. 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…

ssd-virtual-servers-banner-2-728x90

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

Big data

Whether you are wading through enormous log files and click streams, dealing with the social media fire hose, or trying to manage protein sequencing, you are used to big data. Managing the volume, speed, and variety of data produced by today’s applications is top of mind. Dealing with big data in the cloud takes new approaches to storage and analytics. Hadoop and other High Performance Computing (HPC) tools, provide the distributed processing framework necessary to crunch big data.
http://www.rightscale.com/solutions/cloud-computing-uses/big-data.php

PostegresSQL HA

Authored jointly with Scott Mead, Sr. Architect OpenSCG and Architect of PostgresHA.

PostgresHA is Highly Available (HA) PostgreSQL.

 

PostgresHA Architecture

 

 

More in http://www.openscg.com/2013/04/postgresql-clustering/

BUT, Denis Lussier, C-Founder – CTO of EnterpriseDB says…

In general, we do NOT recommend running PostgresHA running synchronus replication. We recommend running PostgreSQL streaming repliction in Asynch mode. Monitoring and alerting must be configured if the slave node falls behind a certain tolerance of keeping up with the master.

 

Virtualization Licenses and Subscriptions – vSphere Standard and Enterprise – Prices

Well, I’m making some researches on Virtualization and I found some prices of licenses and subscriptions of VMware vSphere…

Virtualization Software

VMware vSphere (DIB) add $0.00
VMware ESXi v5.0U2 Embedded Image on Flash Media add $0.00
VMware ESXi v5.1U1 Embedded Image on Flash Media add $0.00
Red Hat Enterprise Virtualization (DIB) add $0.00

Virtualization Licenses and Subscriptions

vSphere Standard v5.x 1CPU License, 1Y Subscription w/Dwngrd Rights [add $1,059.35]
vSphere Standard v5.x 1CPU License, 3Y Subscription w/Dwngrd Rights [add $1,645.92]
vSphere Standard v5.x 1CPU License, 5Y Subscription w/Dwngrd Rights [add $2,119.41] Continue reading Virtualization Licenses and Subscriptions – vSphere Standard and Enterprise – Prices

SQL – LEFT OUTER JOIN adding returned null values

In a SQL with LEFT OUTER JOIN I had to sum some columns but some of them returned with NULL value and the result of it was a NULL.

So imagine that we want to add table1`.`columnA`to `table2`.`columnB`, we do something like this

SELECT *, (table1`.`columnA` + `table2`.`columnB`) AS total

and if some of them is NULL the total will be NULL.

What I had to do was this

SELECT *, (ifnull(`table1`.`columnA`,0 ) + ifnull(`table2`.`columnB`, 0)) AS total

And if you want to put it on codeigniter where is how I made it:

$this->db->select('*, (ifnull(`table1`.`columnA`,0 ) + ifnull(`table2`.`columnB`, 0)) AS total', FALSE);

Note the , FALSE, it has to be there.

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.
http://ellislab.com/codeigniter/user-guide/database/active_record.html