Nginx Ngnix上游超时错误

Nginx Ngnix上游超时错误,nginx,amazon-ec2,yii2,php-7,Nginx,Amazon Ec2,Yii2,Php 7,我已经在AmazonEC2实例上安装了php7和nginx,在yii2中出现以下错误 2016/11/11 07:00:33 [error] 11220#0: *14 upstream timed out (110: Connection timed out) while reading response header from upstream, client: XXX.XX.XXX.111, server: example.com, request: "POST /backend/web

我已经在AmazonEC2实例上安装了php7和nginx,在yii2中出现以下错误

2016/11/11 07:00:33 [error] 11220#0: *14 upstream timed out (110: Connection timed out) 
while reading response header from upstream, client: XXX.XX.XXX.111, server: 
example.com, request: "POST /backend/web/index.php?r=site%2Flogin HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "example.com",
referrer: "http://example.com/backend/web/index.php?r=site%2Flogin"
下面是我的nginx配置文件。(/etc/nginx/conf.d/virtual.conf)

我已经试着做了以下事情,但没有成功:(


fastcgi_pass 127.0.0.1:9000

在端口9000上是否有任何侦听内容?请尝试运行
netstat-atpn | grep9000

这些奇怪的错误是正常的。对于yii2,更喜欢unix套接字(
/var/run/php7.0-fpm.sock;
或其他什么)。在PHP-fpm配置文件(
PHP-fpm.conf
)中设置
请求终止超时=30s
。在
PHP.ini
中设置
最大执行时间=30

这几乎是一个防故障的配置。根据每次更改使用
nginx-t
进行调试,并检查前端

    location ~ \.php$ {
            root            /usr/share/nginx/html;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include         fastcgi_params;
    }
如果仍然不起作用,请将
客户端\u max\u body\u size 128M;
增加到1 GB

可以编译一些发行版,将PHP文件保存在
/etc/nginx/snippets/
。在
/etc/nginx/fastcgi\u参数上运行
cat
,检查它有什么。如果添加
/path/to/root/$fastcgi\u脚本名称
,则包括
fastcgi\u索引
,确保它是
fastcgi\u参数;

显然,要认真地检查
php fpm.conf
中的TCP或unix套接字配置

下面的内容在逻辑上是不正确的。600s是一段很长的时间。但有时它可以工作。在
nginx.conf
上小心使用它:

proxy_connect_timeout  600s;
proxy_send_timeout  600s;
proxy_read_timeout  600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;

您的上游应用程序是否正在侦听和可用?我通常使用类似“telnet”的简单方法来测试上游应用程序是否正在侦听和响应:

[root@ip-10-0-1-1 opt]# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
^]close

telnet> close
Connection closed.
[root@ip-10-0-1-1 opt]#
如果进程未运行(但已打开以供访问),您将看到“连接被拒绝”错误:

[root@ip-10-0-1-1 opt]# telnet localhost 8000
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

HTH

最有可能是上游出现错误。请确保您可以连接到,并且防火墙没有阻止任何内容

如果使用fastcgi(PHP-FPM),则需要调整fastcgi\u读取\u超时而不是代理读取\u超时


此处的更多信息:

首先检查
netstat-atpn | grep 9000
,通常有许多连接需要关闭,如下所示:

tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
max_execution_time = 30
尝试在
/etc/php/7.x/fpm/pool.d/www.conf
上启用
request\u terminate\u timeout
,并给出终止请求的持续时间。如下所示:

request_terminate_timeout=30s
并确保在
php.ini
上启用
max\u execution\u time
,如下所示:

tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
tcp 1257 0 localhost:9000 localhost:46650 CLOSE_WAIT
max_execution_time = 30

现在出现另一个错误。我已授予0777权限以访问根目录下的资产文件夹ugin权限。异常(配置无效)“yii\base\InvalidConfigException”和消息“该目录不可由Web进程写入:/usr/share/nginx/html/xxxx/backend/Web/assets”现在收到另一个错误。我已将0777权限授予根权限中的assets文件夹ugin。异常(无效配置)“yii\base\InvalidConfigException”和消息“该目录不可由Web进程写入:/usr/share/nginx/html/xxxx/backend/Web/assets”现在收到另一个错误。我已将0777权限授予根权限中的assets文件夹ugin。异常(无效配置)“yii\base\InvalidConfigException”带有消息“该目录不可由Web进程写入:/usr/share/nginx/html/xxxx/backend/Web/assets”禁用SELinux.Run
$chgrp/usr/share/nginx/html/xxxx/backend/Web/assets$chmod g+w/usr/share/nginx/html/xxxx/backend/Web/assets
对于CentOS,
www-data
用于Ubuntu。使用
ps
检查
user
group
,检查您的代码是否有错误,类似的问题我们在修复php代码后解决。如下回答: