Skip to content

Commit 4f05537

Browse files
sushicodeurdunglas
authored andcommitted
Troubleshooting error 502 "upstream sent too big header while reading response header from upstream" (#676)
* Troubleshooting error 502 on some api routes "upstream sent too big header while reading response header from upstream" * Update troubleshooting.md
1 parent 063814a commit 4f05537

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

extra/troubleshooting.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,58 @@ jms_serializer:
4040
```
4141
4242
The JMS Serializer service is available as `jms_serializer`.
43+
44+
## "upstream sent too big header while reading response header from upstream" 502 Error
45+
46+
Some of your API calls fail with a 502 error and the logs for the api container shows the following error message `upstream sent too big header while reading response header from upstream`.
47+
48+
This can be due to the cache invalidation headers that are too big for NGINX. When you query the API, API Platform adds the ids of all returned entities and their dependencies in the headers like so : `Cache-Tags: /entity/1,/dependent_entity/1,/entity/2`. This can overflow the default header size (4k) when your API gets larger and more complex.
49+
50+
You can modify the `api/docker/nginx/conf.d/default.conf` file and set values to `fastcgi_buffer_size` and `fastcgi_buffers` that suit your needs, like so:
51+
52+
```
53+
server {
54+
root /srv/api/public;
55+
56+
location / {
57+
# try to serve file directly, fallback to index.php
58+
try_files $uri /index.php$is_args$args;
59+
}
60+
61+
location ~ ^/index\.php(/|$) {
62+
# Comment the next line and uncomment the next to enable dynamic resolution (incompatible with Kubernetes)
63+
fastcgi_pass php:9000;
64+
#resolver 127.0.0.11;
65+
#set $upstream_host php;
66+
#fastcgi_pass $upstream_host:9000;
67+
68+
# Bigger buffer size to handle cache invalidation headers expansion
69+
fastcgi_buffer_size 128k;
70+
fastcgi_buffers 4 256k;
71+
72+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
73+
include fastcgi_params;
74+
# When you are using symlinks to link the document root to the
75+
# current version of your application, you should pass the real
76+
# application path instead of the path to the symlink to PHP
77+
# FPM.
78+
# Otherwise, PHP's OPcache may not properly detect changes to
79+
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
80+
# for more information).
81+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
82+
fastcgi_param DOCUMENT_ROOT $realpath_root;
83+
# Prevents URIs that include the front controller. This will 404:
84+
# http://domain.tld/index.php/some-path
85+
# Remove the internal directive to allow URIs like this
86+
internal;
87+
}
88+
89+
# return 404 for all other php files not matching the front controller
90+
# this prevents access to other php files you don't want to be accessible.
91+
location ~ \.php$ {
92+
return 404;
93+
}
94+
}
95+
```
96+
97+
You then need to rebuild your containers by running `docker-compose build`.

0 commit comments

Comments
 (0)