Reputation: 3024
I have a situation with an ubuntu server that is configured to run with nginx and fastcgi. The problem is that after a restart any request is giving 502 bad gateway in browser.
In error log the error looks like this:
connect() to unix:/var/run/fastcgi.socket-4 failed (2: No such file or directory) while connecting to upstream
after I create the file manually (i do not know if this is correct) the error is changing to:
connect() to unix:/var/run/fastcgi.socket-4 failed (111: Connection refused) while connecting to upstream
nginx server has configuration settings for each website like this:
location ~ \.php$ {
fastcgi_pass unix:/var/run/fastcgi.socket-4;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /document_root/$fastcgi_scr
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_index index.php;
fastcgi_intercept_errors on;
}
Note that I am quite new to nginx, however I have experience and knowhow in apache and php.
Upvotes: 2
Views: 6636
Reputation: 42799
The 502 bad gateway
error means that the backend server (which is php in your case) is not functioning properly, and since it was related to a server restart, I guessed it would be related to it not starting on boot time.
Since I didn't know the service name, running sudo service --status-all
lists all services on the system.
After finding the php service name which turned to be spawn-fcgi
in your case, you can start it using
sudo service spawn-fcgi start
or
sudo /etc/init.d/spawn-fcgi start
You need to make sure that it auto starts on boot, to find that you can easily google how to make a service start on boot, it's very simple
Upvotes: 4