About the connection between nginx and php-fpm that did not go well
I was trying to run a server with nginx and fastcgi, but for some reason it didn't display properly due to an error, so I wrote a memo.
Even when I tried sending a request normally, I got a badgateway 502 error.
I tried to find the cause
I tried searching.
Look at nginx's access.log
The access.log shows that requests are coming in properly...
Look at the error.log of php-fpm
There is no log either.
At this point, you can see that there seems to be a problem between nginx and php-fpm.
Specifically, how to write nginx.conf?
Which process is listening on which port?
I tried various things, but in the end I got the error message, "There's a mistake in the port number!", so I tried the following command.
netstat -antp
By the way, the meanings of the options are as follows:
- -a(all) Show all sockets
- -n(numeric) Outputs numbers without performing name resolution
- -t(tcp) show tcp
- -p(program) Display process (program) name
Then, the following was displayed.
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2427/php-fpm: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1004/nginx: master
Nginx uses port80, but php-fpm uses port9000.
The port number for fastcgi_pass in nginx.conf was written incorrectly.
The error this time was that php-fpm was listening on port9000,
The problem was that the nginx.conf settings were listening on port80 and fastcgi_pass (php-fpm listening host port) was 127.0.0.1:80.
fastcgi_pass 127.0.0.1:9000;
I fixed it as above!
comment