I am getting an issue on hitting the Laravel API. The following issue occurs:
The API is hit and returns an incorrect response twice, with the request body being appended along with a 200 status code. For example, if the request body is:
{
"email": "[email protected]",
"password": "string"
}
The response appears as:
{
"email": "[email protected]",
"password": "string"
}{"message":"Invalid credentials"}
This happens two times with a 200 status code.
On the third hit, the API correctly returns a 401 status code with the expected response:
{
"message": "Invalid credentials"
}
The correct response occurs only once, while the wrong response occurs twice.
Could you help identify what might be causing this inconsistent behavior?
The issue seems to be related to the Nginx configuration, as this issue does not occur on local development. Restarting Docker temporarily resolves the issue, but it reappears after some time.
This is my nginx configuration code:
upstream backend {
server web:9000;
}
server {
listen 80;
index index.php index.html;
server_name domain_name;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
client_max_body_size 100M;
fastcgi_read_timeout 1800;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass backend; # Use the upstream backend
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
2