[英]How can I configure Nginx to route a specific request pattern to a specific php-fpm upstream hosting a Symfony application?
I'm developing an application composed of 3 microservices . 我正在开发一个由3个微服务组成的应用程序 。 Each microservice is a Symfony 4 application . 每个微服务都是Symfony 4应用程序 。
To route all my request made to this application I'm using Nginx . 要将我对此应用程序的所有请求路由,我正在使用Nginx 。
There are, for now, three url patterns, one for each microservice. 目前,有三个url模式,每个微服务一个。 One of them is the ^/auth
pattern which allow the access to the authentication API through the php-fpm upstream. 其中一个是^/auth
模式,它允许通过php-fpm upstream访问身份验证API。
I've tried many things but for now this is the closest Nginx configuration I have from my objective. 我已经尝试了很多东西但是现在这是我从目标中得到的最接近的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;
}
}
With this configuration, this is what append : 使用此配置,这是附加内容:
While Nginx is handling the request : 虽然Nginx正在处理请求:
So my questions are : 所以我的问题是:
Thank you for your answers :) 谢谢您的回答 :)
Try to move the include fastcgi_params;
尝试移动include fastcgi_params;
line upward 向上排
something like this: 这样的事情:
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.