Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

m_Faizan's avatar

laravel prepends post request body with response data

I have production set up for my Laravel API with Docker(version: 26.1.1), Nginx(image: nginx:stable-alpine), and PHP(image: php:7.4-fpm-alpine) on Debian vps.

For a few days I'm struggling with a strange problem: The result I receive for my API request does not only include the valid response, but also the parameters that I send along with the post request;

Request: { "email": "[email protected]", "password": "xxxxxxx" }

Response: { "email": "[email protected]", "password": "xxxxxxx" }{ "token": "xxxxxxxxxxxxxxxxxxxxxxxxxx", "type": "xxxxxxxx" }

This response does not come with a content-type: application/json but as text/html. It seems like the post request body is prepended to the response data of my API. This results in a JSON parse error on my client. After restarting the nginx server, the problem disappeared temporarily and then started again. I checked in both Nginx and laravel logs, there would be no error.

nginx/default.conf:

server {
    listen 80;
    index index.php index.html;
    server_name xx.xxx.com;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;

    location ~ \.php$ {
        fastcgi_intercept_errors on;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        include fastcgi.conf;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param  REQUEST_METHOD $request_method;
        fastcgi_param HTTP_MOD_REWRITE on;
    }

    ...

}

docker-compose.yml:

Note: Another thing I want to let you know that when I try this whole setup without docker with same versions of nginx and php on another debian vps, it works fine without any issue.

0 likes
2 replies
vincent15000's avatar

I don't understand what you need.

It's normal that the reponse includes additional attributes like the token.

Please or to participate in this conversation.