ubuntu服务器重启后,nginx 502网关错误 [英] nginx 502 bad gateway after ubuntu server restart

查看:483
本文介绍了ubuntu服务器重启后,nginx 502网关错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了配置为与Nginx和fastcgi一起运行的ubuntu服务器的情况.问题在于,重新启动后,任何请求都会在浏览器中提供502错误的网关.

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服务器具有每个网站的配置设置,如下所示:

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;
                        }

请注意,我对nginx还是很陌生,但是我在apache和php中有经验和专业知识.

Note that I am quite new to nginx, however I have experience and knowhow in apache and php.

推荐答案

502 bad gateway错误表示后端服务器(在您的情况下为php)无法正常运行,并且由于它与服务器重启有关,我猜想这可能与启动时没有启动有关.

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.

由于我不知道服务名称,因此运行sudo service --status-all会列出系统上的所有服务.

Since I didn't know the service name, running sudo service --status-all lists all services on the system.

找到适合您情况的php服务名称后,您可以使用

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

sudo /etc/init.d/spawn-fcgi start

您需要确保它在启动时自动启动,要发现您可以轻松地通过Google搜索如何在启动时启动服务,这很简单

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

这篇关于ubuntu服务器重启后,nginx 502网关错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆