我遇到了麻烦,我的php-fpm设置。 也许你们可以把我指向正确的方向。 首先,一切工作正常。 但时不时地,我会得到503错误。 一旦我重新加载网站,这些错误就消失了。 他们只出现在php网站,并没有孤立到一个域或一个框架。 我收到了PHPmyAdmin,Wordpress和Typo3中的503错误。 那些是我testing的3个站点。 他们是在单独的虚拟主机,并有不同的PHP-FMP池,但他们共享相同的PHP-FPM主要步骤。
我运行的服务器是Apache 2.4(MPM-Event Workers),没有mod_php或者cgi / fastcgi。 相反,我使用mod_proxy和mod_proxy_fcgi将每个.php文件传递给我的php-fpm进程。 有一点要注意的是,服务器还没有投入生产,所以几乎没有任何stream量。 服务器硬件是强大的,12个VCores和32 GB的RAM。
我的mod_proxy和mod_proxy_fcgi设置是默认的 – 我没有改变任何东西。
我的虚拟主机configuration(代理部分):
<FilesMatch "\.php$"> SetHandler "proxy:unix:///opt/php-5.6.11/var/run/php5-fpm-mywebsite.sock|fcgi://mywebsite/" </FilesMatch> <Proxy fcgi://mywebsite/ enablereuse=on retry=0> </Proxy>
注意:我以前在Proxy指令中有最多10个,似乎更频繁地产生了503错误。 现在我已经删除了最多= 10,似乎发生less。 虽然可能只是巧合。
我的PHP-FPM池configuration(相关部分):
listen = var/run/php5-fpm-mywebsite.sock listen.owner = mywebsite listen.group = www-data listen.mode = 0660 listen.backlog = 65535 user = mywebsite group = www-data listen.allowed_clients = 127.0.0.1 pm = ondemand pm.max_children = 20 pm.process_idle_timeout = 15s request_terminate_timeout = 300s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = no
我的PHP-FPMconfiguration(相关部分):
emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 10 events.mechanism = epoll
我的PHP.ini为PHP-FPM主进程。 这里没有列出的所有东西都是默认的php设置,或者不应该是相关的:
memory_limit = 400M upload_max_filesize = 20M post_max_size = 20M max_execution_time = 600 max_input_time = -1 max_input_vars = 10000 suhosin.get.max_vars = 10000 suhosin.post.max_vars = 10000 [Zend] zend_extension=/opt/php-5.6.11/lib/php/extensions/no-debug-non-zts-20131226/ioncube.so zend_extension=opcache.so opcache.revalidate_freq=0 ;opcache.validate_timestamps=0 opcache.max_accelerated_files=50000 opcache.memory_consumption=256 opcache.interned_strings_buffer=16 opcache.fast_shutdown=1 [APC] extension=apcu.so apc.enabled=1 apc.shm_segments = 1 apc.shm_size=256M apc.ttl=7200 apc.user_ttl=7200 apc.gc_ttl=3600 apc.stat=1 apc.enable_cli=0 apc.file_update_protection=2 apc.max_file_size=2M apc.include_once_override=0 apc.mmap_file_mask=/tmp/apc.XXXXXX apc.cache_by_default=1 apc.use_request_time=1 apc.slam_defense=0 apc.stat_ctime=0 apc.canonicalize=1 apc.write_lock=1 apc.report_autofilter=0 apc.rfc1867=0 apc.rfc1867_prefix =upload_ apc.rfc1867_name=APC_UPLOAD_PROGRESS apc.rfc1867_freq=0 apc.rfc1867_ttl=3600 apc.lazy_classes=0 apc.lazy_functions=0 extension=memcache.so extension=memcached.so
注意:Memcached有1 GB的内存分配给它。
Apache错误日志
从apache error.log实际的错误信息。 如果总是一样的话,错误信息。 (我已经启用了详细的代理日志logging):
[proxy:debug] [pid 141760:tid 140526898214656] mod_proxy.c(1159): [client myclient] AH01143: Running scheme unix handler (attempt 0), referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy_fcgi:debug] [pid 141760:tid 140526898214656] mod_proxy_fcgi.c(879): [client myclient] AH01076: url: fcgi://mywebsite//var/www/html/mywebsite/htdocs/typo3site/website/index.php proxyname: (null) proxyport: 0, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy_fcgi:debug] [pid 141760:tid 140526898214656] mod_proxy_fcgi.c(886): [client myclient] AH01078: serving URL fcgi://mywebsite//var/www/html/mywebsite/htdocs/typo3site/website/index.php, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy:debug] [pid 141760:tid 140526898214656] proxy_util.c(2147): AH00942: FCGI: has acquired connection for (mywebsite) [proxy:debug] [pid 141760:tid 140526898214656] proxy_util.c(2200): [client myclient] AH00944: connecting fcgi://mywebsite//var/www/html/mywebsite/htdocs/typo3site/website/index.php to mywebsite:8000, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy:debug] [pid 141760:tid 140526898214656] proxy_util.c(2237): [client myclient] AH02545: fcgi: has determined UDS as /opt/php-5.6.11/var/run/php5-fpm-mywebsite.sock, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy:debug] [pid 141760:tid 140526898214656] proxy_util.c(2409): [client myclient] AH00947: connected //var/www/html/mywebsite/htdocs/typo3site/website/index.php to httpd-UDS:0, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy_fcgi:error] [pid 141760:tid 140526898214656] [client myclient] AH01067: Failed to read FastCGI header, referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy_fcgi:error] [pid 141760:tid 140526898214656] (104)Connection reset by peer: [client myclient] AH01075: Error dispatching request to : , referer: http://mywebsite/website/typo3/install/index.php?TYPO3_INSTALL[type]=cleanup [proxy:debug] [pid 141760:tid 140526898214656] proxy_util.c(2162): AH00943: FCGI: has released connection for (mywebsite)
现在我的问题:
我如何解决在我的Web服务器上反复出现的PHP 503错误?
我的想法:
我不是那些东西的出口,所以我很难搞清楚。 与PHP-FPM Apache似乎并不常见,大多数谷歌的结果是基于Nginx,这并没有多大的帮助。
也许这里有人可以帮助我?
非常感谢!!
删除代理行上的enablereuse = on选项,以便读取
<Proxy fcgi://mywebsite/ retry=0>
这解决了“错误调度请求:,引用…”的问题。
正如其他post所build议的那样,当通过Unix套接字运行PHP-FPM守护进程时,不应该使用enablereuse=on 。
mod_proxy_fcgi的Apache文档通过说明来证实这一点,
UDS目前不支持连接重用
UDS表示Unix域套接字,这意味着当您运行PHP-FPM作为套接字(.sock)时,而不是默认的TCP端口方法。
Nathan Zachary详细介绍了如何将Apache + PHP-FPMconfiguration为套接字以及其他相关主题。
在使用enablereuse = on和UDS进行POST后,我立即经历了疯狂的,不可预知的Apache响应。 一旦我删除了enablereuse = on并重新启动服务,问题就完全消失了。
更多的症状和debugging这个问题从mod_h2人 。
我有同样的确切问题,并试图了解是什么原因后,我发现, 原因是一个错误的插件。
特别是我们通过禁用这个wordpress插件来解决这个问题: https : //wordpress.org/plugins/custom-css-js/
我们使用的是PHP 7和wordpress 4.5.6。
所以对我们来说不是由于configuration错误的PHP,Apache或任何caching系统。 没有问题是没有资源可用(CPU / RAM)的问题。 问题是由于一个错误的插件。
很难find哪个插件导致了这个问题。 我们明白感谢phpdebugging选项,所以我build议将下面的这些行添加到wp-config.php来debugging:
define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors',0);
好运!
是listen = var/run/php5-fpm-mywebsite.sock是否正确?
至于虚拟主机的情况,你可以尝试这些configuration:
Apache(在VirtualHost标签)
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/DOCUMENT_ROOT_OF_VHOST/$1
PHP-FPM池
listen = 127.0.0.1:9000
如果您对.htaccess没有任何疑虑,build议使用nginx 。