upstream sent too big header while reading response header from upstream - php
I am getting these kind of errors:
2014/05/24 11:49:06 [error] 8376#0: *54031 upstream sent too big header while reading response header from upstream, client: 107.21.193.210, server: aamjanata.com, request: "GET /the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https://aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20ht
Always it is the same. A url repeated over and over with comma separating. Can't figure out what is causing this. Anyone have an idea?
Update: Another error:
http request count is zero while sending response to client
Here is the config. There are other irrelevant things, but this part was added/edited
fastcgi_cache_path /var/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
# Upstream to abstract backend connection(s) for PHP.
upstream php {
#this should match value of "listen" directive in php-fpm pool
server unix:/var/run/php5-fpm.sock;
}
And then in the server block:
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass php;
fastcgi_read_timeout 3000;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}`
Add the following to your conf file
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
If nginx is running as a proxy / reverse proxy
that is, for users of ngx_http_proxy_module
In addition to fastcgi, the proxy module also saves the request header in a temporary buffer.
So you may need also to increase the proxy_buffer_size and the proxy_buffers, or disable it totally (Please read the nginx documentation).
Example of proxy buffering configuration
http {
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
Example of disabling your proxy buffer (recommended for long polling servers)
http {
proxy_buffering off;
}
For more information: Nginx proxy module documentation
Plesk instructions
I combined the top two answers here
In Plesk 12, I had nginx running as a reverse proxy (which I think is the default). So the current top answer doesn't work as nginx is also being run as a proxy.
I went to Subscriptions | [subscription domain] | Websites & Domains (tab) | [Virtual Host domain] | Web Server Settings.
Then at the bottom of that page you can set the Additional nginx directives which I set to be a combination of the top two answers here:
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
upstream sent too big header while reading response header from upstream is nginx's generic way of saying "I don't like what I'm seeing"
Your upstream server thread crashed
The upstream server sent an invalid header back
The Notice/Warnings sent back from STDERR overflowed their buffer and both it and STDOUT were closed
3: Look at the error logs above the message, is it streaming with logged lines preceding the message? PHP message: PHP Notice: Undefined index:
Example snippet from a loop my log file:
2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice: Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
... // 20 lines of same
PHP message: PHP Notice: Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice: Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
PHP message: PHP Notice: Undef
2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "ta_convert.php on line 1090
PHP message: PHP Notice: Undefined index: Firstname
you can see in the 3rd line from the bottom that the buffer limit was hit, broke, and the next thread wrote in over it. Nginx then closed the connection and returned 502 to the client.
2: log all the headers sent per request, review them and make sure they conform to standards (nginx does not permit anything older than 24 hours to delete/expire a cookie, sending invalid content length because error messages were buffered before the content counted...). getallheaders function call can usually help out in abstracted code situations php get all headers
examples include:
<?php
//expire cookie
setcookie ( 'bookmark', '', strtotime('2012-01-01 00:00:00') );
// nginx will refuse this header response, too far past to accept
....
?>
and this:
<?php
header('Content-type: image/jpg');
?>
<?php //a space was injected into the output above this line
header('Content-length: ' . filesize('image.jpg') );
echo file_get_contents('image.jpg');
// error! the response is now 1-byte longer than header!!
?>
1: verify, or make a script log, to ensure your thread is reaching the correct end point and not exiting before completion.
I have a django application deployed to EBS, and I am using Python 3.8 running on 64bit Amazon Linux 2. The following method worked for me (note folder structure might be DIFFERENT if you're using previous Linux versions. For more, see official documentation here
Make the .platform folder and its sub-directory as shown below:
|-- .ebextensions # Don't put nginx config here
| |-- django.config
|-- .platform # Make ".platform" folder and its subfolders
|-- nginx
| -- conf.d
| -- proxy.conf
Note that proxy.conf file should be placed inside .platform folder, NOT .ebextensions folder or the .elasticbeanstalk folder. The extension should end with .conf NOT .config.
Inside the proxy.conf file, copy & paste these lines directly:
client_max_body_size 50M;
large_client_header_buffers 4 32k;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 32k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
There is no need to issue command to restart nginx (for Amazon Linux 2)
Deploy the source code to elastic beanstalk again.
Add:
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
To server{} in nginx.conf
Works for me.
We ended up realising that our one server that was experiencing this had busted fpm config resulting in php errors/warnings/notices that'd normally be logged to disk were being sent over the FCGI socket. It looks like there's a parsing bug when part of the header gets split across the buffer chunks.
So setting php_admin_value[error_log] to something actually writeable and restarting php-fpm was enough to fix the problem.
We could reproduce the problem with a smaller script:
<?php
for ($i = 0; $i<$_GET['iterations']; $i++)
error_log(str_pad("a", $_GET['size'], "a"));
echo "got here\n";
Raising the buffers made the 502s harder to hit but not impossible, e.g native:
bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=121 iterations=30 < HTTP/1.1 502 Bad Gateway
size=109 iterations=33 < HTTP/1.1 502 Bad Gateway
size=232 iterations=33 < HTTP/1.1 502 Bad Gateway
size=241 iterations=48 < HTTP/1.1 502 Bad Gateway
size=145 iterations=51 < HTTP/1.1 502 Bad Gateway
size=226 iterations=51 < HTTP/1.1 502 Bad Gateway
size=190 iterations=60 < HTTP/1.1 502 Bad Gateway
size=115 iterations=63 < HTTP/1.1 502 Bad Gateway
size=109 iterations=66 < HTTP/1.1 502 Bad Gateway
size=163 iterations=69 < HTTP/1.1 502 Bad Gateway
[... there would be more here, but I piped through head ...]
fastcgi_buffers 16 16k; fastcgi_buffer_size 32k;:
bash-4.1# for it in {30..200..3}; do for size in {100..250..3}; do echo "size=$size iterations=$it $(curl -sv "http://localhost/debug.php?size=$size&iterations=$it" 2>&1 | egrep '^< HTTP')"; done; done | grep 502 | head
size=223 iterations=69 < HTTP/1.1 502 Bad Gateway
size=184 iterations=165 < HTTP/1.1 502 Bad Gateway
size=151 iterations=198 < HTTP/1.1 502 Bad Gateway
So I believe the correct answer is: fix your fpm config so it logs errors to disk.
Faced the same problem when running Symfony app in php-fpm and nginx in docker containers.
After some research found that it was caused by php-fpm's stderr written to nginx logs. I.e. php warnings (which is generated intensively in Symfony debug mode) was duplicated in docker logs php-fpm:
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleAwareListener::onKernelFinishRequest"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: "NOTICE: PHP message: [debug] Notified event "kernel.terminate" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelTerminate"."
[09-Jul-2021 12:25:46] WARNING: [pool www] child 38 said into stderr: ""
and docker logs nginx:
2021/07/09 12:25:46 [error] 30#30: *2 FastCGI sent in stderr: "ller" to listener "OblgazAPI\API\Common\Infrastructure\EventSubscriber\LegalAuthenticationChecker::checkAuthentication".
PHP message: [debug] Notified event "kernel.controller_arguments" to listener "Symfony\Component\HttpKernel\EventListener\ErrorListener::onControllerArguments".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelResponse".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse".
PHP message: [debug] Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse".
PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest".
PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest".
PHP message: [debug] Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleAwareListener::onKernelFinishRequest".
PHP message: [debug] Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ErrorListener::logKernelException".
PHP message: [debug] Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".
and then nginx logs ended with
2021/07/09 12:25:46 [error] 30#30: *2 upstream sent too big header while reading response header from upstream ...
and I got 502 error.
Increasing the fastcgi_buffer_size in nginx config helped, but it seems more like a suppression the problem, not a treatment.
A better solution is to disable php-fpm to send logs by FastCGI. Found it can be made by setting fastcgi.logging=0 in php.ini (by default it is 1). php docs.
After changing it to 0, the problem goes away and nginx logs looks much cleaner docker logs nginx:
172.18.0.1 - - [09/Jul/2021:12:36:02 +0300] "GET /my/symfony/app HTTP/1.1" 401 73 "-" "PostmanRuntime/7.26.8"
172.18.0.1 - - [09/Jul/2021:12:36:04 +0300] "GET /my/symfony/app HTTP/1.1" 401 73 "-" "PostmanRuntime/7.26.8"
and all php-fpm logs are still in their place in php-fpm log.
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;
it worked for me when I increased the numbers
If you're using Symfony framework:
Before messing with Nginx config, try to disable ChromePHP first.
1 - Open app/config/config_dev.yml
2 - Comment these lines:
#chromephp:
#type: chromephp
#level: info
ChromePHP pack the debug info json-encoded in the X-ChromePhp-Data header, which is too big for the default config of nginx with fastcgi.
Source: https://github.com/symfony/symfony/issues/8413#issuecomment-20412848
This is still the highest SO-question on Google when searching for this error, so let's bump it.
When getting this error and not wanting to deep-dive into the NGINX settings immediately, you might want to check your outputs to the debug console.
In my case I was outputting loads of text to the FirePHP / Chromelogger console, and since this is all sent as a header, it was causing the overflow.
It might not be needed to change the webserver settings if this error is caused by just sending insane amounts of log messages.
I am not sure that the issue is related to what header php is sending.
Make sure that the buffering is enabled. The simple way is to create a proxy.conf file:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
And a fascgi.conf file:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
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_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 GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
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_buffers 128 4096k;
fastcgi_buffer_size 4096k;
fastcgi_index index.php;
fastcgi_param REDIRECT_STATUS 200;
Next you need to call them in your default config server this way:
http {
include /etc/nginx/mime.types;
include /etc/nginx/proxy.conf;
include /etc/nginx/fastcgi.conf;
index index.html index.htm index.php;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /logs/access.log main;
sendfile on;
tcp_nopush on;
# ........
}
In our case we got this nginx error because our backend generated redirect response with a very long URL:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/?manyParamsHere...
Just for curiosity, we saved that big URL to a file and it size was 4.4 Kb.
Adding two lines to the config file /etc/nginx/conf.d/some_site.conf helped us to fix this error:
server {
# ...
location ~ ^/index\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Add these lines:
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
}
}
Read more about these params at the official nginx documentation.
For Symfony projects, try adding this line to your .env file:
SHELL_VERBOSITY=0
https://symfony.com/doc/current/console/verbosity.html
I will just leave it here, because I spent a crazy amount of time debugging this in my project and only this particular solution worked 100% for me (for the right reasons) and I have never found this answer related to this topic. Maybe someone will find it helpful.
I had this error and I found 3 ways to fix that:
Set SHELL_VERBOSITY=0 or another value < 3 in .env: https://stackoverflow.com/a/69321273/13653732 In this case you disable your PHP logs, but they can be useful for development and debugging.
Set fastcgi.logging=0 in php.ini. It is the same result like above.
Update Symfony from 5.2 to 5.3. I think the old version has a problem with that.
All PHP Symfony logs perceived like errors for Nginx, but PHP worked correctly.
I had Nginx 1.17, PHP 8.0.2, PHP-FPM, Symfony 5.2, Xdebug, Docker.
I tried new versions Nginx 1.21, PHP 8.0.14, but without any result. That problem wasn't with Apache.
I changed Nginx configuration, but also without any result.
I am using Symfony, it has a nice exception page (when the ErrorHandler is used). And this one will put the message of your exception as a header to the response created.
vendor/symfony/error-handler/ErrorRenderer/SerializerErrorRenderer.php
the header is called: X-Debug-Exception
So be careful, if you constructed a VERY large exception message, neither nginx nor chrome (limit 256k) nor curl (~128kb) can display your page and make it really hard to debug, what is outputting those big headers.
My suggestion would be to not blindly copy n paste increased buffer sizes into your nginx config, they treat the symptom not the cause.
Related
Nginx + Php-FPM - upstream response is buffered
Running Wordpress on Nginx + Php-FPM. We are getting these kind of warning message in our error logs: [warn] 25518#25518: *34774 an upstream response is buffered to a temporary file /var/lib/nginx/fastcgi/5/01/0000000015 while reading upstream, client: 80.94.93.51, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:" After reading several other threads about similar issues we have modified our configuration by adding proxy_buffers as seen below but this doesn't solve the issue. location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_intercept_errors on; fastcgi_pass unix:/run/php/php7.4-fpm.sock; proxy_buffers 16 16k; proxy_buffer_size 16k; }
PHP-FPM Always Returns 200 Regardless Of NGINX Status Code
I have a PHP-based error page configuration with NGINX and PHP-FPM. However, when I request, for example, example.com/nothing (non-existent page), PHP-FPM returns a 200 status code, and not the correct 404 status code that NGINX returns. This also happens with other errors (ex: example.com/assets returning 200 with PHP-FPM when the status is 403 with NGINX). Essentially what I want PHP-FPM to do is mirror the status code shown by NGINX (override the 200 status code with the one shown by NGINX), so my error pages show the correct information. I am aware that you can change the status code by specifying it when using http_response_code();, but I would rather have the server do this without having me hard-code the proper status code. Error page: <? echo http_response_code(); ?> NGINX error page config: set $errorDocs "/var/www/GLOBAL_RESOURCES/error"; recursive_error_pages on; location ^~ $errorDocs { internal; alias $errorDocs; } #Resolve error asset location 404s location /errorAssets { root $errorDocs; } error_page 404 /404.php; location = /404.php { root $errorDocs; include /etc/nginx/xenon-conf/headers/fpm-params.conf; } PHP-FPM settings: include /etc/nginx/fastcgi_params; include /etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; proxy_intercept_errors on; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; Fast-CGI Config: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 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_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 REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; 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; # PHP only, required if PHP was built with --enable-force-cgi-redirect #fastcgi_param REDIRECT_STATUS 200; Website Config: server { listen 80; server_name example.com www.example.com; access_log /var/log/nginx/example.com.access.log; include /etc/nginx/xenon-conf/headers/php-fpm-enable.conf; include /etc/nginx/xenon-conf/headers/master-failover.conf; set $webRoot "/var/www/example.com"; root $webRoot; } NGINX Config: user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; ### CUSTOM HTTP SERVER MASS IMPORTS ### include /etc/nginx/xenon-conf/websites/*.web; include /etc/nginx/xenon-conf/mapping/*.map; } ### CUSTOM GENERIC STREAM MASS IMPORTS ### include /etc/nginx/xenon-conf/stream/*.conf; Thanks in advance!
If nginx is detecting output from the FastCGI upstream it will consider it as a valid response, even if the upstream (in this case, php-fpm) triggered an error. Disabling display_errors in the PHP-FPM pool fixes this. php_admin_value[display_errors] = Off It prevents the PHP-script from showing error output to the screen, which in turn causes nginx to correctly throw an HTTP 500 Internal Server Error. $ curl -i localhost:8080/test.php?time=`date +%s` HTTP/1.1 500 Internal Server Error Server: nginx ... (no output is shown, empty response) You can still log all errors to a file, with the error_log directive. php_admin_value[error_log] = /var/log/php-fpm/error.log php_admin_flag[log_errors] = on -- Source In order to pass HTTP status codes from nginx to PHP-FPM, you also need to put the following in your PHP handling location: fastcgi_intercept_errors on; According to the manual, this directive: Determines whether FastCGI server responses with codes greater than or equal to 300 should be passed to a client or be intercepted and redirected to nginx for processing with the error_page directive.
The main problem here is that by default php-fpm does not return status code to nginx when exception occurs and display_errors is enabled. TLDR Use some global error handler that set error status code like this: http_response_code(500); This will be passed from php-fpm to nginx and attached to nginx response. How to test this behaviour Create index.php file: <?php // report all errors error_reporting(E_ALL); // do not display errors ini_set("display_errors", 0); // set http response code // http_response_code(500); // throw exception throw new \Exception('TEST UNHANDLED EXCEPTION STATUS CODE'); Create default.conf for nginx server { listen 80; server_name localhost; location / { root /var/www/html; index index.php index.html index.htm; } # pass the PHP scripts to FastCGI server listening on php:9000 location ~ \.php$ { root /var/www/html; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; include fastcgi_params; } } Create docker-compose.yml version: "3.5" services: php: image: php:fpm volumes: - ./index.php:/var/www/html/index.php nginx: depends_on: - php image: nginx:latest volumes: - ./index.php:/var/www/html/index.php - ./default.conf:/etc/nginx/conf.d/default.conf Run project docker-compose up -d Install additional tools for testing php-fpm inside php container To test direct responses from php-fpm wee need to install cgi-fcgi binary docker-compose exec php bash -c 'apt update && apt install -y libfcgi0ldbl' Test responses with display_errors disabled Inside php container, make direct request to php-fpm SCRIPT_NAME=/var/www/html/index.php SCRIPT_FILENAME=/var/www/html/index.php REQUEST_METHOD=GET cgi-fcgi -bind -connect localhost:9000 Response contains status code 500 that is handled by nginx correctly: Status: 500 Internal Server Error X-Powered-By: PHP/8.0.2 Content-type: text/html; charset=UTF-8 Test response from nginx docker-compose exec nginx curl -i localhost Response: HTTP/1.1 500 Internal Server Error Server: nginx/1.19.6 Date: Mon, 22 Feb 2021 11:45:56 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/8.0.2 php-fpm response contains status code 500 and has no body. Nginx use this code in response. Test responses with display_errors enabled Let's enable display_errors in index.php: // do not display errors ini_set("display_errors", 1); Inside php container, make direct request to php-fpm SCRIPT_NAME=/var/www/html/index.php SCRIPT_FILENAME=/var/www/html/index.php REQUEST_METHOD=GET cgi-fcgi -bind -connect localhost:9000 Response: X-Powered-By: PHP/8.0.2 Content-type: text/html; charset=UTF-8 <br /> <b>Fatal error</b>: Uncaught Exception: TEST UNHANDLED EXCEPTION STATUS CODE in /var/www/html/index.php:12 Stack trace: #0 {main} thrown in <b>/var/www/html/index.php</b> on line <b>12</b><br /> Test response from nginx docker-compose exec nginx curl -i localhost Response HTTP/1.1 200 OK Server: nginx/1.19.6 Date: Mon, 22 Feb 2021 11:47:29 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/8.0.2 <br /> <b>Fatal error</b>: Uncaught Exception: TEST UNHANDLED EXCEPTION STATUS CODE in /var/www/html/index.php:12 Stack trace: #0 {main} thrown in <b>/var/www/html/index.php</b> on line <b>12</b><br /> php-fpm response is missing status code 500 but has a body. Nginx treats this as normal response with status 200. Test responses with display_errors enabled and header explicitly set to 500 Let's explicitly set response status code with display_errors on. // set http response code http_response_code(500); Test php-fpm response: SCRIPT_NAME=/var/www/html/index.php SCRIPT_FILENAME=/var/www/html/index.php REQUEST_METHOD=GET cgi-fcgi -bind -connect localhost:9000 Response: Status: 500 Internal Server Error X-Powered-By: PHP/8.0.2 Content-type: text/html; charset=UTF-8 <br /> <b>Fatal error</b>: Uncaught Exception: TEST UNHANDLED EXCEPTION STATUS CODE in /var/www/html/index.php:12 Stack trace: #0 {main} thrown in <b>/var/www/html/index.php</b> on line <b>12</b><br /> Test Nginx response docker-compose exec nginx curl -i localhost Response HTTP/1.1 500 Internal Server Error Server: nginx/1.19.6 Date: Mon, 22 Feb 2021 11:52:38 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/8.0.2 <br /> <b>Fatal error</b>: Uncaught Exception: TEST UNHANDLED EXCEPTION STATUS CODE in /var/www/html/index.php:12 Stack trace: #0 {main} thrown in <b>/var/www/html/index.php</b> on line <b>12</b><br /> php-fpm response has status code 500 and body. Nginx uses body and status code from php-fpm. How to fix A possible fix I can think of is global error handler that catch every unhandled error and explicitly set proper error status code.
nginx - 502 Bad Gateway for some ajax requests
I get 502 Bad Gateway for some requests on my server. I get it for some particular AJAX requests but if I replay the failed request in the console, it works (wtf). In nginx/error.log it says [error] 13867#0: *74180 recv() failed (104: Connection reset by peer) while reading response header from upstream My website is in PHP. Thanx
I had similar problem on wordpress site. add these lines inside http block of /etc/nginx/nginx.conf file. fastcgi_temp_file_write_size 10m; fastcgi_busy_buffers_size 512k; fastcgi_buffer_size 512k; fastcgi_buffers 16 512k; If it still not working also add this line client_max_body_size 50M;
I had similar problem with my gitlab setup on nginx. What helped solve my problem was to higher max client's body size by client_max_body_size 50m directive inside http block of /etc/nginx/nginx.conf file.
Script times out after 240 seconds
I'm running an Nginx + PHP-FPM server and I have a script that is supposed to execute over 30 minutes. After 240 seconds it ceases to function and returns a 502 Gateway error from Nginx. PHP-FPM Log for the execution: [03-May-2013 19:52:02] WARNING: [pool www] child 2949, script '/var/www/shell/import_db.php' (request: "GET /shell/import_db.php") execution timed out (239.971196 sec), terminating [03-May-2013 19:52:02] WARNING: [pool www] child 2949 exited on signal 15 (SIGTERM) after 540.054237 seconds from start [03-May-2013 19:52:02] NOTICE: [pool www] child 3049 started Nginx log for the execution: 2013/05/03 19:52:02 [error] 2970#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 98.172.80.203, server: www.example.net, request: "GET /shell/import_db.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.example.net" I've run this script on an apache+suphp server and it executes flawlessly. Nonethless, I am including: set_time_limit(0); at the top of my script. The max_execution_time according to phpinfo() is 1800 seconds (this was originally 300, I bumped it up to this in an attempt to get it working). FastCGI Nginx Configuration: ## Fcgi Settings include fastcgi_params; fastcgi_connect_timeout 60; fastcgi_send_timeout 180s; fastcgi_read_timeout 600s; fastcgi_buffer_size 4k; fastcgi_buffers 512 4k; fastcgi_busy_buffers_size 8k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors off; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; # nginx will buffer objects to disk that are too large for the buffers above fastcgi_temp_path /tmpfs/nginx/tmp 1 2; #fastcgi_keep_conn on; # NGINX 1.1.14 expires off; ## Do not cache dynamic content I've restarted php-fpm and nginx to no avail. What setting or configuration am I missing from this or that I could check?
When you run nginx with php-fpm, nginx tries to so stay connected with php-fpm's children. You should set the following directive to change that: fastcgi_keep_conn off;
PHP-FPM and Nginx: 502 Bad Gateway
Configuration Ubuntu Server 11.10 64 bit Amazon AWS, Ec2, hosted on the cloud t1.micro instance Before I write anything else, I'd like to state that I've checked both nginx 502 bad gateway and Nginx + PHP-FPM 502 Bad Gateway threads, which unfortunately haven't helped me in this regard. The issue appears to be rather common: a misconfiguration of nginx or php-fpm can lead to a 502 Bad Gateway error, which is something that I haven't been able to get rid of. Note that this appears even when I go to my domain root, without specifying any particular directory. I'm running an Amazon EC2 webserver, with port 9000 enabled, port 80 open, etc. The question in particular is, how can I get rid of this nasty error? Or, better yet, how can I get php5-fpm to actually work. What I Have Attempted so Far Mostly consistent editing of configuration files, notably php-fpm.conf and nginx.conf. i. php-fpm.conf I've added the following, which hasn't quite helped much: ;;;;;;;;;;;;; ; Fpm Start ; ;;;;;;;;;;;;; ;pm.start_servers = 20 ;pm.min_spare_servers = 5 ;pm.max_spare_servers = 35 Now, afterward I tried including my configuration files: include=/etc/php5/fpm/*.conf Which only screwed me even further. Full Configuration ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative paths in this configuration file are relative to PHP's install ; prefix (/usr). This prefix can be dynamicaly changed by using the ; '-p' argument from the command line. ; Include one or more files. If glob(3) exists, it is used to include a bunch of ; files from a glob(3) pattern. This directive can be used everywhere in the ; file. ; Relative path can also be used. They will be prefixed by: ; - the global prefix if it's been set (-p arguement) ; - /usr otherwise ;include=/etc/php5/fpm/*.conf ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; [global] ; Pid file ; Note: the default prefix is /var ; Default Value: none pid = /var/run/php5-fpm.pid ; Error log file ; Note: the default prefix is /var ; Default Value: log/php-fpm.log error_log = /var/log/php5-fpm.log ; Log level ; Possible Values: alert, error, warning, notice, debug ; Default Value: notice log_level = notice ; If this number of child processes exit with SIGSEGV or SIGBUS within the time ; interval set by emergency_restart_interval then FPM will restart. A value ; of '0' means 'Off'. ; Default Value: 0 ;emergency_restart_threshold = 0 ; Interval of time used by emergency_restart_interval to determine when ; a graceful restart will be initiated. This can be useful to work around ; accidental corruptions in an accelerator's shared memory. ; Available Units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 emergency_restart_interval = 0 ; Time limit for child processes to wait for a reaction on signals from master. ; Available units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 ;process_control_timeout = 0 ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. ; Default Value: yes daemonize = no ;;;;;;;;;;;;; ; Fpm Start ; ;;;;;;;;;;;;; ;pm.start_servers = 20 ;pm.min_spare_servers = 5 ;pm.max_spare_servers = 35 ;;;;;;;;;;;;;;;;;;;; ; Pool Definitions ; ;;;;;;;;;;;;;;;;;;;; ; Multiple pools of child processes may be started with different listening ; ports and different management options. The name of the pool will be ; used in logs and stats. There is no limitation on the number of pools which ; FPM can handle. Your system will tell you anyway :) ; To configure the pools it is recommended to have one .conf file per ; pool in the following directory: include=/etc/php5/fpm/pool.d/*.conf ii. nginx.conf In all honesty this configuration is a smattering of a few websites I've visited, but I can tell you that before this 502 Bad Gateway business, the server was running fine (without PHP working. Period.). The issue primarily lies in the fact that something is terribly, terribly wrong. And now, when I try to do a service php5-fpm restart, it hangs in what I'm guessing is an infinite loop or something, which I can't even CTRL-C out of. Full Configuration user www-data; worker_processes 1; pid /var/run/nginx.pid; events { worker_connections 64; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush off; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 80; server_name ec2-xx-xx-xx-xx.compute-x.amazonaws.com; location ~ ^(.+\.php)(.*)$ { root /home/wayvac/public; fastcgi_pass unix:/var/run/php5-fpm.pid; #fastcgi_pass 127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm. fastcgi_index index.php; set $document_root2 $document_root; if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; } fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root2$fastcgi_path_info; include fastcgi_params; fastcgi_param DOCUMENT_ROOT $document_root2; } access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { root /home/wayvac/public; index index.html index.htm index.php; } location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { # Some basic cache-control for static files to be sent to the browser expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } #include drop.conf; #include php.conf; } }
If anyone finds this page by encountering the same problem I had, I found the answer here. For those of you who can't be bothered to click and work it out for themselves... ;) The Condition: Ubuntu or Debian server with NGINX and PHP 5.3 works fine but upgrading PHP to 5.4 gives 502 Bad Gateway errors. Looking for services running on port 9000 (typically running netstat -lp or similar) returns nothing. The fix: Open /etc/php5/fpm/pool.d/www.conf and make a note of the 'listen' parameter (in my case /var/run/php5-fpm.sock): ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on ; a specific port; ; 'port' - to listen on a TCP socket to all addresses on a ; specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. listen = /var/run/php5-fpm.sock and replace the fastcgi_pass variable in your vhost with the location you just noted. So this sample symfony2 configuration (taken from here): # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ ^/(app|app_dev)\.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } becomes this: # pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock location ~ ^/(app|app_dev)\.php(/|$) { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } Then restart nginx: sudo /etc/init.d/nginx restart Note: replace ~ ^/(app|app_dev)\.php(/|$) { with ~ ^/index\.php(/|$) { if you're not on SF2** Hope this saves someone a little bit of time :) Edit Of course, you could change the listen = /var/run/php5-fpm.sock to listen = 127.0.0.1:9000 in /etc/php5/fpm/pool.d/www.conf then restart php5-fpm (which would save you from having to change your vhosts), but you have to assume they changed php5-fpm to run through a socket rather than listening on port 9000 for a reason. Edit2 If you're still experiencing 502 error see this answer.
Try setting these values, it solves problem in fast-cgi fastcgi_buffer_size 16k; fastcgi_buffers 4 16k;
I made all this similar tweaks, but from time to time I was getting 501/502 errors (daily). This are my settings on /etc/php5/fpm/pool.d/www.conf to avoid 501 and 502 nginx errors… The server has 16Gb RAM. This configuration is for a 8Gb RAM server so… sudo nano /etc/php5/fpm/pool.d/www.conf then set the following values for pm.max_children = 70 pm.start_servers = 20 pm.min_spare_servers = 20 pm.max_spare_servers = 35 pm.max_requests = 500 After this changes restart php-fpm sudo service php-fpm restart
If you met the problem after upgrading php-fpm like me, try this: open /etc/php5/fpm/pool.d/www.conf uncomment the following lines: listen.owner = www-data listen.group = www-data listen.mode = 0666 then restart php-fpm.
Don't forget that php-fpm is a service. After installing it, make sure you start it: # service php-fpm start # chkconfig php-fpm on
For anyone else struggling to get to the bottom of this, I tried adjusting timeouts as suggested as I didn't want to stop using Unix sockets...after lots of troubleshooting and not much to go on I found that this issue was being caused by the APC extension that I'd enabled in php-fpm a few months back. Disabling this extension resolved the intermittent 502 errors, easiest way to do this was by commenting out the following line : ;extension = apc.so This did the trick for me!
You should see the error log. By default, its location is in /var/log/nginx/error.log In my case, 502 get way because of: GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local" 2016/05/25 11:57:28 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local" 2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local" 2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local" When we know exactly what is wrong, then fix it. For these error, just modify the buffer: fastcgi_buffers 16 512k; fastcgi_buffer_size 512k;
The port was changed to 9001 in 5.4, just changing the port from 9000 to 9001 in the nginx conf and in php-fpm configuration worked for me.
Hope this tip will save someone else's life. In my case the problem was that I ran out of memory, but only slightly, was hard to think about it. Wasted 3hrs on that. I recommend running: sudo htop or sudo free -m ...along with running problematic requests on the server to see if your memory doesn't run out. And if it does like in my case, you need to create swap file (unless you already have one). I have followed this tutorial to create swap file on Ubuntu Server 14.04 and it worked just fine: http://www.cyberciti.biz/faq/ubuntu-linux-create-add-swap-file/
I've also found this error can be caused when writing json_encoded() data to MySQL. To get around it I base64_encode() the JSON. Please not that when decoded, the JSON encoding can change values. Nb. 24 can become 24.00
All right after trying every solution on the web I ended up figuare out the issue using very simple method , first I cheked php-fpm err log cat /var/log/php5-fpm.log and the most repeated error was " WARNING: [pool www] server reached pm.max_children setting (5), consider raising it " I edit PHP-fpm pools setting nano /etc/php5/fpm/pool.d/www.conf I chenged This Line pm.max_children = 5 To new Value pm.max_children = 10 BTW I'm using low end VPS with 128MB ram As everyone else I was thinkin redusing pm.max_children will make my server run faster consume less memory , but the setting we using were too low tho even start PHP-fpm process . I hope this help others since I found this after 24 hour testing and failing , ever my webhost support were not able to solve the issue .
I'm very late to this game, but my problem started when I upgraded php on my server. I was able to just remove the .socket file and restart my services. Then, everything worked. Not sure why it made a difference, since the file is size 0 and the ownership and permissions are the same, but it worked.
Before messing with Nginx config, try to disable ChromePHP first. 1 - Open app/config/config_dev.yml 2 - Comment these lines: chromephp: type: chromephp level: info ChromePHP pack the debug info json-encoded in the X-ChromePhp-Data header, which is too big for the default config of nginx with fastcgi.
In your NGINX vhost file, in location block which processes your PHP files (usually location ~ \.php$ {) through FastCGI, make sure you have next lines: proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; After that don't forget to restart fpm and nginx. Additional: NGINX vhost paths /etc/nginx/sites-enabled/ - Linux '/usr/local/etc/nginx/sites-enabled/' - Mac Restart NGINX: sudo service nginx restart - Linux brew service restart nginx - Mac Restart FPM: Determine fpm process name: - systemctl list-unit-files | grep fpm - Linux - brew services list | grep php - Mac and then restart it with: sudo service <service-name> restart - Linux brew services restart <service-name> - Mac
Maybe this answer will help: nginx error connect to php5-fpm.sock failed (13: Permission denied) The solution was to replace www-data with nginx in /var/www/php/fpm/pool.d/www.conf And respectively modify the socket credentials: $ sudo chmod nginx:nginx /var/run/php/php7.2-fpm.sock