首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一个nginx站点按位置划分的多个fpm套接字

问一个nginx站点按位置划分的多个fpm套接字
EN

Stack Overflow用户
提问于 2018-02-12 19:21:41
回答 1查看 1.1K关注 0票数 1

想象一下nginx中的默认站点。

代码语言:javascript
复制
server {
    listen 80;
    server_name example.com;
}

server {
    listen 80 default_server;
    client_max_body_size 0;
    server_name _;

    index index.php index.html index.htm;
    set $root_path '/www/public';
    root $root_path;

    try_files $uri @rewrite;

    rewrite ^/(?!api/)(.*)/$ /$1 permanent;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php$ {
        fastcgi_index /index.php;

        ##### I THINK LOCATION CONFIG MUST COMES HERE #####
        fastcgi_pass unix:/var/run/php/xxxx.sock;
        ###################################################

        include fastcgi_params;
        fastcgi_split_path_info           ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO           $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED     $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        access_log syslog:server=loghost,facility=local7,tag=nginx,severity=info syslogformat if=$dolog;
    }
}

我们需要在重写(到index.php)之后分离urls,并将它们传递给不同的fpm套接字。

例如,我想使用

fastcgi_pass unix:/var/run/php/1111.sock;用于^/action-1/之类的urls

和

fastcgi_pass unix:/var/run/php/2222.sock;用于其他任何事情

我该怎么做?感谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-13 03:31:41

设置默认套接字,并匹配其他套接字的单独路径。

代码语言:javascript
复制
server {

    ...
    set $php_socket "1";

    if ($uri ~* "^/action-1/") {
        set $php_socket "2";
    }
    ...

    location ~ \.php$ {        
        ...
        if ($php_socket = '1') { fastcgi_pass unix:/var/run/php/1.sock; }
        if ($php_socket = '2') { fastcgi_pass unix:/var/run/php/2.sock; }
        ...
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48753975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档