大网数据广告活动
服务器运维问答

Different php-fpm pools in single nginx vhost

· 52CE 我爱测

I searched for a while online but couldn't succeed. My problem is as follows: I want to use different php-fpm pools in one nginx vhost based conditionally on the nature of the request but couldn't find a way to configure the loca…

问题原文

原帖链接 · Daniel Müller · CC BY-SA 3.0

I searched for a while online but couldn't succeed. My problem is as follows:

I want to use different php-fpm pools in one nginx vhost based conditionally on the nature of the request but couldn't find a way to configure the location ~ \.php$ {...} part of my vhost config to support two different worker pools.

Only solution I figured out is redirecting the web request to another nginx site.

Thank you in advance

已采纳解答

原帖链接 · Tero Kilkanen · CC BY-SA 3.0

You can work along the following principle:

set $upstream /path/to/defaultfpm-socket;

location /first {
    set $upstream /path/to/fpm1-socket;
}

location /second {
    set $upstream /path/to/fpm2-socket;
}

fastcgi_pass $upstream;

So, here we set the $upstream variable to the PHP5-FPM socket we want to use depending on the location (part of the URI). We then use the variable with fastcgi_pass to pass the request to that PHP5-FPM instance.

location rules can use normal nginx matching rules, like regex, prefix etc. matching. It is a good idea to set a default value so that requests are always parsed.

You need to also include other FastCGI statements in the configuration.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。