- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在装有 nginx 和 php5-fpm 的 Debian Jessie 机器上运行 shopware 5,我们经常遇到 502 Bad Gateway。这主要发生在后端,当较长的操作像缩略图创建一样工作时,即使这是在单个 ajax 请求的小块中完成的。
具有 64 GB RAM 和 16 核的已用服务器完全处于休眠状态,因为它上面没有实际流量。我们目前将其用作暂存系统,除非我们已修复所有此类错误。
然后在 nginx-error 日志中可以找到以下几行:
[error] 20524#0: *175 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "POST /backend/MediaManager/createThumbnails HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20524#0: *175 no live upstreams while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "POST /backend/Log/createLog HTTP/1.1", upstream: "fastcgi://php-fpm", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20524#0: *175 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "GET /backend/login/getLoginStatus?_dc=1457014588680 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20522#0: *209 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "GET /backend/login/getLoginStatus?_dc=1457014618682 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
也许值得注意的是,一开始出现了很多"*175 connect" 错误,然后最后出现了"*209 connect"。
我会尽量只发布与该主题相关的重要行,并会删除所有被注释掉的行。
/etc/php5-fpm/pool.d/www.conf:
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
/etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
## MIME types.
include /etc/nginx/mime.types;
default_type application/octet-stream;
## Default log and error files.
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
## Use sendfile() syscall to speed up I/O operations and speed up
## static file serving.
sendfile on;
## Handling of IPs in proxied and load balancing situations.
# set_real_ip_from 192.168.1.0/24; # set to your proxies ip or range
# real_ip_header X-Forwarded-For;
## Timeouts.
client_body_timeout 60;
client_header_timeout 60;
keepalive_timeout 10 10;
send_timeout 60;
## Reset lingering timed out connections. Deflect DDoS.
reset_timedout_connection on;
## Body size.
client_max_body_size 10m;
## TCP options.
tcp_nodelay on;
## Optimization of socket handling when using sendfile.
tcp_nopush on;
## Compression.
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_http_version 1.1;
gzip_min_length 10;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
gzip_vary on;
gzip_proxied any; # Compression for all requests.
gzip_disable "msie6";
## Hide the Nginx version number.
server_tokens off;
## Upstream to abstract backend connection(s) for PHP.
upstream php-fpm {
server unix:/var/run/php5-fpm.sock;
# server 127.0.0.1:9000;
## Create a backend connection cache.
keepalive 32;
}
## Include additional configs
include /etc/nginx/conf.d/*.conf;
## Include all vhosts.
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-available/site.conf:
server {
listen 80;
listen 443 ssl;
server_name xxxxxxxx.com;
root /var/www/shopware;
## Access and error logs.
access_log /var/log/nginx/xxxxxxxx.com.access.log;
error_log /var/log/nginx/xxxxxxxx.com.error.log;
## leaving out lots of shopware/mediafiles-related settings
## ....
## continue:
location ~ \.php$ {
try_files $uri $uri/ =404;
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## required for upstream keepalive
# disabled due to failed connections
#fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SHOPWARE_ENV $shopware_env if_not_empty;
fastcgi_param ENV $shopware_env if_not_empty; # BC for older SW versions
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
client_max_body_size 24M;
client_body_buffer_size 128k;
## upstream "php-fpm" must be configured in http context
fastcgi_pass php-fpm;
}
}
现在怎么办?如果我应该为这个问题提供更多信息,请让我现在。
应用来自@peixotorms 的 nginx- 和 fpm-settings 后,nginx-logs 中的错误更改为:
30 upstream timed out (110: Connection timed out) while reading response header from upstream
但问题本身并没有解决。它只是另一张脸...
最佳答案
这对您来说可能听起来很奇怪,但您的问题很可能是由于您在套接字而不是 tcp 端口上运行 PHP。当您在套接字配置上有大约 300 个并发请求(有时更少)时,您将开始看到 502 错误(和其他错误)。
此外,您的 pm.max_children
太低了,除非您希望将您的服务器限制为最多同时处理 5 个 php 请求:http://php.net/manual/en/install.fpm.configuration.php
以这种方式配置它,这些错误应该会消失:
为您的 nginx.conf 更改以下值:
worker_processes 4;
worker_rlimit_nofile 750000;
# handles connection stuff
events {
worker_connections 50000;
multi_accept on;
use epoll;
}
upstream php-fpm {
keepalive 30;
server 127.0.0.1:9001;
}
你的/etc/php5-fpm/pool.d/www.conf
(使用这些设置是因为您有足够的 RAM 和 CPU)
[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
listen.backlog = 65000
pm = dynamic
pm.max_children = 1024
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 16
pm.max_requests = 10000
同时将此添加到您的 location ~\.php$ {
block :
location ~ \.php$ {
try_files $uri $uri/ =404;
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## required for upstream keepalive
# disabled due to failed connections
#fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SHOPWARE_ENV $shopware_env if_not_empty;
fastcgi_param ENV $shopware_env if_not_empty; # BC for older SW versions
fastcgi_keep_conn on;
fastcgi_connect_timeout 20s;
fastcgi_send_timeout 60s;
fastcgi_read_timeout 60s;
fastcgi_pass php-fpm;
}
编辑:
将 /etc/php5/fpm/php.ini
文件中的以下值更改为此并重新启动:
safe_mode = Off
output_buffering = Off
zlib.output_compression = Off
max_execution_time = 900
max_input_time = 900
memory_limit = 2048M
post_max_size = 120M
file_uploads = On
upload_max_filesize = 120M
关于php - 502 Bad Gateway : nginx, php5-fpm,175/209 connect() 连接到上游时失败(111:连接被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35776015/
我正在尝试使用 FPM 模块安装 PHP,但我根本做不到。我在 Mac OS Big Sur 上 brew install php74 --with-fpm --with-debug --with-c
我在使用 traefik 设置 mailcow 时遇到问题,遇到网关超时。我对 nextcloud 也有这个问题,所以我真的很感兴趣,是什么导致了这些网关超时问题。 我猜这与端口 9000 和上游 p
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我在 Red Hat Linux 服务器上安装了 PHP 7,但显然由于在服务器上运行一些命令来配置 PHP,我丢失了 php-fpm.sock文件。 任何人都可以帮助我了解文件的内容吗? 最佳答案
我的情况是这样的,我有两个 Docker 容器: 在端口 9000 上运行 PHP-FPM 运行 nginx 并拥有 PHP 文件(PHP-FPM 容器应该可以访问这些文件吗?) 我不断收到以下错误:
项目的 Git 存储库:https://github.com/tombusby/docker-laravel-experiments (撰写本文时 HEAD 为 823fd22)。 这是我的 dock
我正在尝试获取在 Windows 上运行的 Homestead Improved Vagrant VM 实例。请参阅Homestead Improved on Github 。我正在遵循这个简单的介绍
我知道我真的很接近这个,但我无法得到最后一部分 在职的。我几乎可以肯定它与 WordPress 有关 容器和 PHP 容器需要在同一个目录下吗?所以 PHP可以处理那个目录下的文件吗?我一直在努力 一
501 25131 1 0 9:31下午 ?? 0:00.37 /usr/local/opt/php/sbin/php-fpm --nodaemonize 501 2
我正在尝试在 Docker 镜像上设置 php-fpm。 这是我的 docker-compose.yml 中的服务: wordpress-service: build: context:
我在使用PHP-FPM遇到这个奇怪的问题。首先,我不是PHP方面的专家。我正在构建一个应用程序,PHP将仅与MySQL通信以推送和提取数据。 问题: 我有一个Dockerfile,在其中我对PHP-F
这是我的 docker-compose.yml version: '2' services: web: image: nginx:latest ports:
我一直在尝试让 php-fpm (w nginx) 与默认端口 (9000) 一起工作,但它不起作用。我正在尝试使用 php 7.1(也尝试过 7.0 和 5.6)。服务启动正常,我还可以在 ss/n
我正在努力寻找适用于 php-fpm 的监视器配置。 这是我试过的: ### Monitoring php-fpm: the parent process. check process php-fpm
在 fastcgi_finish_request(); 语句后在我的 php 脚本中实现了一些后处理后,我担心会出现一些差异。 看起来 PHP 没有在 fastcgi_finish_request
当一个特别长的字符串被打印到 php5-fpm.log 时,该字符串在末尾被截断并显示“...”(不带引号)以表明它已被截断。我怎样才能让它显示整个字符串而不考虑长度? 如果需要的话,我将 Nginx
php fpm 网站上的文档说 php fpm 从 5.3.3 开始是 coe php 的一部分 我正在运行 5.3.10,如何检查它是否正常工作?我以为这是在端口上运行的服务? 最佳答案 假设你在
我有一个运行 Apache/2.2.22 (Debian)、PHP 5.6.17 作为 FPM 和 MySQL 5.6.25 的服务器。 该项目使用名为 Redaxo 的 CMS 运行(我认为这并不重
我刚刚安装了一个 nginx+php-fpm 服务器。一切似乎都很好,只是 PHP-FPM 从不将错误写入其日志。 fpm.conf [default] listen = /var/run/php-f
本文实例讲述了PHP-FPM 设置多pool及配置文件重写操作。分享给大家供大家参考,具体如下: 重写配置文件 1、清空php配置文件 命令:> /usr/local/php/etc/p
我是一名优秀的程序员,十分优秀!