0

I have installed nginx and PHP into my machine. I want to know the difference between these to configuration when using PHP-fpm.

> fastcgi_pass    127.0.0.1:9000; 
            or  
>fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

which configuration is good for production servers, what is the benefit, what is the difference between the two configs?

Sruthin Kumar TK
  • 161
  • 1
  • 2
  • 9

1 Answers1

1

fastcgi_pass 127.0.0.1:9000; is a TCP connection.

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; is a unix socket connection.

Both are suitable for production use, TCP allows you to connect via IP on an arbitrary port. The socket is filesystem based.

If you have a web server and php running on separate servers then the TCP approach would be the way to go. If they're on the same server, the socket configuration would be better . Sockets run faster due to not having the TCP overhead.

Brian Lee
  • 17,904
  • 3
  • 41
  • 52
  • regarding this tutorial, it says to change like this fastcgi_pass 127.0.0.1:9000; (https://medium.com/@richb_/tweaking-nginx-and-php-fpm-configuration-to-fix-502-bad-gateway-errors-and-optimise-performance-on-17465f41fd87) – Sruthin Kumar TK Jul 14 '18 at 07:22
  • Nothing I posted is incorrect. [Here are others verifying this](https://unix.stackexchange.com/questions/91774/performance-of-unix-sockets-vs-tcp-ports)... [And some more](https://serverfault.com/questions/195328/unix-socket-vs-tcp-ip-hostport) – Brian Lee Jul 14 '18 at 07:31
  • [Another source](https://www.lowendtalk.com/discussion/7289/nginx-php-fpm-unix-socket-or-tcp-ip-for-fastcgi-pass).... [And another source](http://iallex.com/php_fpm-of-unix-sockets-vs-tcp-ports/) – Brian Lee Jul 14 '18 at 07:33
  • [How fast are Unix sockets](https://blog.myhro.info/2017/01/how-fast-are-unix-domain-sockets).... [Benchmarking IP and Unix sockets](https://blog.myhro.info/2017/01/benchmarking-ip-and-unix-domain-sockets-for-real) – Brian Lee Jul 14 '18 at 07:36