0

I'm following a guide to set up a ubuntu VPS as a nginx webserver for wordpress.

When setting up Nginx and PHP the guide I'm using suggests I uncomment this line in /etc/nginx/sites-available/default:

fastcgi_pass 127.0.0.1:9000;

Having done this, although the server's welcome page works, I get a 502 bad gateway error when going to a php file I created (containing phpinfo)

However, when I uncomment this line instead:

fastcgi_pass unix:/var/run/php5-fpm.sock;

The php file appears to load successfully

Can anyone explain what each line does and why the one I used works but the one in the tutorial does not?

1 Answer 1

1

When you use "fastcgi_pass 127.0.0.1:9000;" nginx tries to connect to fastcgi using a TCP connection on port 9000 in order to "interpret" your php files. When using "fastcgi_pass unix:/var/run/php5-fpm.sock;" it tries to bind to a socket file which does not use the network stack. It is a manner of preference, a TCP socket is usually easier to setup due to permissions issues. You can't connect at the same time to a TCP port and a SOCKET.

6
  • OK, so any suggestions on how I can get the TCP method to work? Or at least to work out why it's broken...
    – harryg
    Feb 27, 2013 at 21:15
  • First try to see if php5-fpm listens on TCP port 9000. You find this out with: $ sudo netstat -pant | grep 9000. If it does not listen then you should check if it's started and if it's started and still not listening, look into the config file of php5-fpm. Or just use the socket option.
    – pincoded
    Feb 28, 2013 at 8:34
  • The config file should look something like this: listen = 127.0.0.1:9000 ;listen = /var/run/php-fpm/php-fpm.sock so listen 127.... is active and listen /var/run is commented.
    – pincoded
    Feb 28, 2013 at 8:51
  • OK great thanks. Sorry I'm a bit of a beginner when it comes to sysadmining. Will give it a try when I get a chance. But basically there is no problem with the socket option?
    – harryg
    Feb 28, 2013 at 9:31
  • If it functions, then there is no problem. Some say it is even faster through sockets because it bypasses the network stack.
    – pincoded
    Feb 28, 2013 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .