【问题标题】:Symfony and nginx - 502 Bad Gateway error when calling APIsSymfony 和 nginx - 调用 API 时出现 502 Bad Gateway 错误
【发布时间】:2021-08-03 16:30:12
【问题描述】:

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

我确信问题来自我的 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;
}

【问题讨论】:

  • 我认为你的 nginx 无法与 php 通信

标签: php symfony authentication nginx


【解决方案1】:

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

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;
}

【讨论】:

    猜你喜欢
    • 2019-09-15
    • 2016-10-23
    • 1970-01-01
    • 2018-11-12
    • 2018-04-23
    • 1970-01-01
    • 2013-07-16
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多