I have a strange problem with a nginx-fpm application ( one docker container with nginx and another one with a php fpm).
When i post (or put, patch) a request the body of the request is added in the response before the response (this issue appear 70 to 90% of my request, it's not always appearing):
the curl:
curl --location --request POST 'http://localhost/foo' \
--header 'Content-Type: application/json' \
--data-raw '{
"data": "lorem ipsm"
}'
the response:
{
"data": "lorem ipsm"
}<h1>foo</h1>
i have a simple nginx config:
default.conf
location ~ ^/foo\.php(/|$) {
fastcgi_pass server:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location /foo {
try_files $uri /foo.php;
}
fastcgi param
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/$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;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
php file
<?php
echo '<h1>foo</h1>';
Nginx version: nginx/1.14.0
Php version: 7.2
Do you have an idea about this issue ?
I was encountering this issue as well using nginx and php-fpm7.4.
I'm not sure what causes the issue, but I resolved the issue by passing: fastcgi_param PHP_VALUE "auto_prepend_file= \n allow_url_include=Off" ; in the location section on the nginx .conf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With