I don't understand what you need.
It's normal that the reponse includes additional attributes like the token.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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:
version: "3"
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ../:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
network_mode: host
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
environment:
DB_HOST: xxxxxxxxx
DB_PORT: xxxxxxxxx
DB_DATABASE: xxxxxxxxx
DB_USERNAME: xxxxxxxxx
DB_PASSWORD: xxxxxxxxx
REDIS_HOST: xxxxxxxx
volumes:
- ../:/var/www/html
command: |
sh -c "chown -R www-data:www-data /var/www/html && php-fpm"
network_mode: host
redis:
build:
context: ./redis
dockerfile: Dockerfile
container_name: redis
command: sh -c 'chown -R redis:redis /data && redis-server'
volumes:
- ../../outside_project_folder/data/redis:/data
network_mode: host
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.
Please or to participate in this conversation.