Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I just spun up a new Rackspace cloud server and ran the following:

apt-get install php5 nginx php-fpm

When I navigate to the IP address, I see the default Nginx message. I then copied my /etc/nginx/sites-available/default file from another working setup I have:

server {

  listen 80;
  server_name localhost;

  root /srv/www;
  index index.php;

  location / {
    try_files $uri $uri/ /controllers$uri.php;
    location ~ \.php$ {
      try_files $uri /index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
      }
   }
}

I created index.php in /srv/www and started nginx and php-fpm:

/etc/init.d/nginx start
/etc/init.d/php5-fpm start

I'm getting a 502 Bad Gateway error. Am I doing something wrong?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Since I can't add comment, I'll post it as an answer...

Check /etc/php5/fpm/pool.d/www.conf (or the file in there) if it's set to run on TCP or UNIX socket. Also check if the PHP is actually running. And look into the log files /var/log/php5-fpm.log or /var/log/php5-fpm/* and /var/log/nginx/* (depends on settings).

You should find the cause of the error there.

share|improve this answer
    
This is a sane answer. There would be no need to post it as a comment. Comments give you no reuputation :) –  Christopher Perrin Dec 13 '12 at 20:59
    
I opened /etc/php5/fpm/pool.d/www.conf and found listen = /var/run/php5-fpm.sock. I changed it to listen = 127.0.0.1:9000 and everything is working now. I totally forgot about that one-line configuration! Thanks! –  David Dec 13 '12 at 21:04

The bad gateway error means that the php process is responding with an error. Can you check your php error log? Also try placing a file test.php with <?php phpinfo(); ?> @ /srv/www/ and then try to hit that domain directly from the command line of your server ala:

curl http://127.0.0.1:9000/test.php;

Have you checked the obvious things like you have a file @ /srv/www/index.php? Have you run ps aux and grepped for nginx and php to make sure they are running?

How about running: netstat -an | grep LISTEN to make sure the php-fpm daemon is listening?

share|improve this answer
    
I ran netstat -an | grep LISTEN and saw that nothing was listening on 127.0.0.1:9000. I opened /etc/php5/fpm/pool.d/www.conf and found listen = /var/run/php5-fpm.sock. I changed it to listen = 127.0.0.1:9000 and everything is working now. I thought this was the default setting and I forgot to check it. Thanks! –  David Dec 13 '12 at 21:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.