Saturday idle come to nothing, try to install and deploy under YII2, installation process no problem, but deployed to Nginx encountered 502 bad gatewary problem, toss a half a day to fix. This is the problem I have not encountered in deploying YII2, so I am here to remember.
1. Installation and deployment environment
Operating system: Macos,php version: 5.6,nginx version: 1.10.1,YII2 version: 2.0.
Installation of 2,YII2
The installation of Yii2 is simple, refer to the official website manual. I installed the yii2-app-advanced (Yii 2 Advanced Project Template), the project address on GitHub, follow the installation instructions in the Readme step-by-step, this is not much to say.
Deployment of 3,YII2 on Nginx
In fact, the yii2-app-advanced Project Readme for how to deploy on Nginx has been said very clearly, follow the steps should not have any problems. But when I was deployed, I stole a lazy, directly to the Readme in the deployment parameters to use, the result of the 502 bad gateway caused the error.
HTTP status code in the 5-bit response code is caused by the server side, so look at the Nginx log:
Error log:
See upstream: "FastCGI://127.0.0.1:9090" Here, the port seems wrong, so look at the configuration of the virtual host:
Then look at the configuration of the PHP-FPM:
Sure enough, it is the Nginx virtual host designated FASTCGI server listening port is wrong, this will cause Nginx did not get the FASTCGI server response. So when the browser makes a request, Nginx returns a 502 status code to the browser, telling the browser that the upstream fastcgi server is not responding.
4, solve
In the Nginx virtual host, the port specified by the Fastcgi_pass modified correctly, this error is resolved.
5, summary
(1) HTTP status Code 5 the beginning of the error is caused by the server side, 502 Bad Gateway is due to the server as a gateway or agent (Web server) when attempting to execute the request, from the upstream server (fastcgi server) received an invalid response.
(2) Fastcgi_pass is a configuration directive for the Ngx_http_fastcgi_module module, which specifies the address of the FASTCGI server, which is described in the Nginx document as follows:
1 Syntax:fastcgi_pass address;2 Default:-3Context:location,if inch Location4 5 sets the address of a FastCGI server. The address can be specified as a domain name or IP address, and a port:6Fastcgi_pass localhost:9000;7 8Or as a unix-Domain socket path:9Fastcgi_pass unix:/tmp/Fastcgi.socket;Ten One IfA domain name resolves to several addresses, all of them would be usedinchA round-robin fashion.inchaddition, an address can specified as a server group.
Reference:
HTTP status Code
Fastcgi_pass
| Syntax: |
fastcgi_pass address; |
| Default: |
— |
| Context: |
location,if in location |
Remember to troubleshoot 502 bad Gatewary error when you deploy a YII2 project