[英]Symfony and nginx - 502 Bad Gateway error when calling APIs
I use docker (php7.4 and nginx) for running my Symfony 5 application, I implemented Bearer authentication using firebase/php-jwt
, and can get a token successfully, but when I try to call the APIs using the token in the header, I get 502 Bad Gateway
( See the Error ) from nginx. I use docker (php7.4 and nginx) for running my Symfony 5 application, I implemented Bearer authentication using
firebase/php-jwt
, and can get a token successfully, but when I try to call the APIs using the token in the header,我从 nginx 得到502 Bad Gateway
(参见错误)。
I am sure that the problem comes from my nginx configs, because when I use Symfony Local Web Server, it works.我确信问题来自我的 nginx 配置,因为当我使用 Symfony 本地 Web 服务器时,它可以工作。
nginx configuration: 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;
}
I increased the buffer size and solved the problem:我增加了缓冲区大小并解决了问题:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.