Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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?

share|improve this question
up vote 1 down vote accepted

When you use "fastcgi_pass;" 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.

share|improve this answer
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 '13 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 '13 at 8:34
The config file should look something like this: listen = ;listen = /var/run/php-fpm/php-fpm.sock so listen 127.... is active and listen /var/run is commented. – pincoded Feb 28 '13 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 '13 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 '13 at 15:20

Your Answer


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.