I faced up with the issue that seems to be NGINX issue. So, I created the API platform custom operation and when I request the route I see the following output:
7#7: *9 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: 172.31.0.1, server: , request: "GET /i18/device_help_tips HTTP/1.1", upstream: "fastcgi://172.31.0.3:9000", host: "localhost:8080"
My API Platform config is the following:
App\Api\Entity\DeviceHelpTip:
properties:
attributes:
order:
sorting: 'DESC'
collectionOperations:
get_i18:
method: 'GET'
path: '/i18/device_help_tips'
controller: 'App\Api\Controller\DeviceHelpTip\PerformI18Request'
security: "is_granted('ROLE_CONTENT_MANAGER') or is_granted('ROLE_MOBILE') or is_granted('ROLE_ADMIN')"
Interesting fact: if I remove in the security section one of the roles it will work correctly. Also I have the bearer auth here. If I try the request data with token - it will work fine, if no token - error mentioned above
Controller:
<?php
namespace App\Api\Controller\DeviceHelpTip;
use App\Api\Handler\DeviceHelpTipI18RequestHandler;
use Symfony\Component\HttpFoundation\Request;
class PerformI18Request
{
private DeviceHelpTipI18RequestHandler $deviceHelpTipI18RequestHandler;
public function __construct(DeviceHelpTipI18RequestHandler $deviceHelpTipI18RequestHandler)
{
$this->deviceHelpTipI18RequestHandler = $deviceHelpTipI18RequestHandler;
}
public function __invoke($data)
{
$this->deviceHelpTipI18RequestHandler->handle($data);
}
}
NGINX config:
server {
root /srv/api/public;
client_max_body_size 10M;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
# Comment the next line and uncomment the next to enable dynamic resolution (incompatible with Kubernetes)
fastcgi_pass api-backend:9000;
#resolver 127.0.0.11;
#set $upstream_host api-backend;
#fastcgi_pass $upstream_host:9000;
# Bigger buffer size to handle cache invalidation headers expansion
fastcgi_buffer_size 32k;
fastcgi_buffers 8 16k;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
}
I tried to change the fastcgi_buffer_size and fastcgi_buffers but with no result. If you need additional config please let me know in comments. Thanks in advance.