use*_*756 5 php apache nginx docker
我使用 PHP 和 Apache 以及 nginx 进行反向代理,全部都在 Docker 上,并且我有几个长时间运行的调用,这些调用在 60 秒后计时,导致 504 网关超时。我知道我的应用程序被成功调用,因为我正在跟踪 PHP 应用程序的日志,并且我可以看到它正在积极写入日志。每次都是 60 秒超时,但我似乎无法弄清楚该设置在哪里。
我尝试了这篇文章中的建议,但没有任何效果。我已经用一些与时间相关的设置更新了我的 php.ini 文件,并且我已经验证它们是使用 phpinfo 设置的
max_input_time = 0
max_execution_time = 500
Run Code Online (Sandbox Code Playgroud)
我还将内存限制增加到 512,但考虑到每次都会在大约 60 秒内超时,我认为这不是问题。
至于更新 nginx 设置,我最初按照本教程调整 nginx-proxy 超时,但这不起作用。我取消了更改,然后 ssh 进入容器并手动更新 /etc/nginx/nginx.conf,http 部分如下所示
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 500;
proxy_connect_timeout 600;
proxy_send_timeout 600;
send_timeout 600;
client_max_body_size 5000;
client_header_timeout 600;
client_body_timeout 600;
fastcgi_read_timeout 300;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
Run Code Online (Sandbox Code Playgroud)
我确保nginx -s reload在更新 nginx.conf 文件后运行。我不知道还能去哪里寻找,因为我遇到的一切几乎都是我已经做过的事情。还有什么可能导致 nginx 在 60 秒后超时?谢谢
这是我的 PHP dockerfile
FROM php:7.2-fpm-alpine3.7
RUN apk update; \
apk upgrade;
RUN docker-php-ext-install pdo_mysql
RUN apk add --no-cache php7-pear php7-dev gcc musl-dev make
RUN pecl install xdebug
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
Run Code Online (Sandbox Code Playgroud)
问题是 nginx 有它自己的超时。理想情况下,您应该同步 nginx 和 PHP。我无法在这里与 Apache 交谈,因为我不知道您正在使用什么模式(FPM 或 mod_php)运行它。我也不太确定为什么要运行 Nginx 和 Apache,但是,如果您收到 504 响应,并且 PHP 仍在处理请求,则 Nginx 将终止请求并返回 504 响应。Nginx 不像 Apache 那样使用 mod_php 运行,其中进程是同一个。Nginx 将转发请求并等待任何进程返回响应。
请参阅我们的配置中有关 Nginx 超时的以下设置。
# Timeouts
# The client_body_timeout and client_header_timeout directives are
# responsible for the time a server will wait for a client body or
# client header to be sent after request. If neither a body or header
# is sent, the server will issue a 408 error or Request time out.
#
# The keepalive_timeout assigns the timeout for keep-alive connections
# with the client. Simply put, Nginx will close connections with the
# client after this period of time.
#
# Finally, the send_timeout is a timeout for transmitting a response
# to the client. If the client does not receive anything within this
# time, then the connection will be closed. Send the client a "request
# timed out" if the body is not loaded by this time. Default 60.
client_body_timeout 32;
client_header_timeout 32;
# Every 60 seconds server broadcasts Sync packets, so 90 is a conservative upper bound. Default is 65
keepalive_timeout 90;
send_timeout 300;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48307 次 |
| 最近记录: |