Symfony 和 nginx - 调用 API 时出现 502 Bad Gateway 错误
Symfony and nginx - 502 Bad Gateway error when calling APIs
我为 运行 我的 Symfony 5 应用程序使用 docker(php7.4 和 nginx),我使用 firebase/php-jwt
实现了 Bearer 身份验证,并且可以获得令牌成功,但是当我尝试使用 header 中的令牌调用 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;
}
我增加了缓冲区大小并解决了问题:
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;
}
我为 运行 我的 Symfony 5 应用程序使用 docker(php7.4 和 nginx),我使用 firebase/php-jwt
实现了 Bearer 身份验证,并且可以获得令牌成功,但是当我尝试使用 header 中的令牌调用 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;
}
我增加了缓冲区大小并解决了问题:
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;
}