Symfony 和 nginx - 调用 API 时出现 502 Bad Gateway 错误

Ser*_*vin 4 php authentication nginx symfony

我使用 docker (php7.4 和 nginx)来运行我的 Symfony 5 应用程序,我使用 实现了 Bearer 身份验证firebase/php-jwt,并且可以成功获取令牌,但是当我尝试使用标头中的令牌调用 API 时,我得到了502 Bad Gateway参见来自 nginx 的错误)。

我确信问题来自我的 nginx 配置,因为当我使用 Symfony 本地 Web 服务器时,它可以工作。

nginx 配置:

server {
    listen 80;
    server_name my.local;
    root /home/my/public;

    location / {
    try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass my-app:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/my_error.log;
    access_log /var/log/nginx/my_access.log;
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*vin 9

我增加了缓冲区大小并解决了问题:

server {
    server_name my.local;
    root /home/my/public;;

    location / {
    try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass my-app:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    error_log /var/log/nginx/my_error.log;
    access_log /var/log/nginx/my_access.log;
}
Run Code Online (Sandbox Code Playgroud)