我正在开发一个由3个微服务组成的应用程序。每个微服务都是一个 Symfony 4应用程序。
我要使用 Nginx 将我的所有请求路由到此应用程序。
目前有3个网址格式,每个微服务一个。其中之一是^/auth
模式,该模式允许通过上游的php-fpm访问身份验证API。
我已经尝试了很多事情,但是现在这是我最接近目标的Nginx配置。
server {
listen 80;
server_name app.local;
root /app;
# location directive for the authentication API
location ~ ^/auth/ {
root /app/public;
fastcgi_pass auth_api_upstream;
fastcgi_split_path_info ^(/auth)(/.*)$;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root/index.php$fastcgi_path_info;
include fastcgi_params;
}
# ....
# return 404 if other location do not match
location / {
return 404;
}
}
使用此配置,这就是附加内容:
当Nginx正在处理请求时:
我的问题是:
谢谢您的回答:)
答案 0 :(得分:2)
尝试将include fastcgi_params;
行向上移动
类似这样的东西:
server {
listen 80;
server_name app.local;
root /app;
location ~ ^/auth/ {
root /app/public;
set $app_entrypoint /index.php;
fastcgi_pass auth_api_upstream;
fastcgi_split_path_info ^(/auth)(/.*)$;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param DOCUMENT_URI $app_entrypoint;
fastcgi_param REQUEST_URI $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $app_entrypoint;
fastcgi_param SCRIPT_FILENAME $document_root$app_entrypoint;
}
# return 404 if other location do not match
location / {
return 404;
}
}