How to Switch to TCP/IP from Unix Socket in Nginx

On my Prosper202 – Nginx tutorial, I use Unix Socket because it’s faster. But unix socket has some issues with high-loads. So if you’re experiencing 502 or 504 errors, switching to TCP/IP will solve it. So let’s do it.

Open PHP-FPM pool config file:

nano /etc/php5/fpm/pool.d/www.conf

Search for following line and uncomment it,

listen.backlog = 65536

Now search for following line,

listen = /var/run/php5-fpm.sock

And replace it with,

listen = 127.0.0.1:9000

Changes to php-fpm are now done. But there are some changes you should do to Nginx virtual host configurations. Open virtual host file for your domain with following command,

nano /etc/nginx/sites-available/example.com

Look for following line,

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

And replace it with,

fastcgi_pass 127.0.0.1:9000;

Now restart php-fpm,

service php5-fpm restart

Then Nginx’

service nginx restart

And that’s it. You should edit all your virtual host files and make the above change.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button