简体   繁体   English

Magento 为管理员单独设置 PHP-FPM 组

[英]Magento separate PHP-FPM group for admin

I run a Magento webstore with middling traffic levels, running on NGINX with PHP-FPM.我运行一个中等流量水平的 Magento 网络商店,在 NGINX 上运行,使用 PHP-FPM。 The server environment is very powerful with plenty of overhead, so hardware is not a factor.服务器环境非常强大,有很多开销,所以硬件不是一个因素。

We are getting timeouts and errors when running memory intensive operations in the backend, such as exports and some custom indexes.在后端运行内存密集型操作(例如导出和一些自定义索引)时,我们会遇到超时和错误。

Ignoring writing more efficient code and increasing pool sizes across the whole site, we want to explore ways to allocate more resources to the backend without having to reduce possible concurrent connections sizes across the site.忽略编写更高效的代码和增加整个站点的池大小,我们希望探索将更多资源分配给后端的方法,而不必减少站点中可能的并发连接大小。

It has been suggested that we split the admin of the site to a separate server/IP, with different configs.有人建议我们将站点的管理员拆分为具有不同配置的单独服务器/IP。 This would solve our problem, but also be very expensive, and seems like a big leap to solve a non-critical problem.这将解决我们的问题,但也非常昂贵,而且似乎是解决非关键问题的一大飞跃。

Is is possible to associate a different PHP FPM config to something like www.example.com/admin, giving users from different URLS different capabilities?是否可以将不同的 PHP FPM 配置与 www.example.com/admin 之类的内容相关联,从而为来自不同 URL 的用户提供不同的功能?

Yes, it's possible.是的,这是可能的。

In this example, we specify a default pool, pool 1. If the URL is /admin, we will use pool 2.在这个例子中,我们指定了一个默认池,池 1。如果 URL 是 /admin,我们将使用池 2。

http {
    # The usual..

    # PHP FPM/FastCGI server
    upstream    php5p1 { server unix:/var/run/php5-fpm-pool-1.sock; }
    upstream    php5p2 { server unix:/var/run/php5-fpm-pool-2.sock; }
}

server {

    # Default is to use pool 1
    set $custom_php_pool    "1";

    # If is /admin, we use pool 2
    if ($uri ~* "^/admin/") {
        set $custom_php_pool        "2";
    }

    # ...


    location ~ \.php$ {

        # ...

        # Pass to PHP FPM/FastCGI server
        if ($custom_php_pool = '1') { fastcgi_pass php5p1; }
        if ($custom_php_pool = '2') { fastcgi_pass php5p2; }
    }
}

The accepted answer is conceptually correct in demonstrating the multi-pool PHP-FPM setup.接受的答案在演示多池 PHP-FPM 设置时在概念上是正确的。 However, the provided Nginx configuration relies on IF directives considered slow and unsafe .但是,提供的 Nginx 配置依赖于被认为是慢速和不安全的IF 指令。

Optimal Nginx configuration for multiple PHP-FPM pools dependent on URL:取决于 URL 的多个 PHP-FPM 池的最佳 Nginx 配置:

http {
    upstream fastcgi_www {
        server unix:/var/run/php-fpm.sock;
    }

    upstream fastcgi_admin {
        server unix:/var/run/php-fpm-admin.sock;
    }

    map $request_uri $fastcgi_backend {
        default                 fastcgi_www;
        ~^(/index\.php)?/admin  fastcgi_admin;
    }

    server {
        # ...
        fastcgi_pass   $fastcgi_backend;
        # ...
    }
}

The Nginx configuration nginx.conf.sample shipped with Magento 2 can be used after replacing all occurrences of the FastCGI pass directives:在替换所有出现的 FastCGI pass 指令后,可以使用 Magento 2 附带的 Nginx 配置nginx.conf.sample

fastcgi_pass   fastcgi_backend;

with the variable dependent on the request URL:变量依赖于请求 URL:

fastcgi_pass   $fastcgi_backend;

Modified nginx.conf.sample saved as /var/www/magento2/nginx.conf can be reused:修改后的nginx.conf.sample保存为/var/www/magento2/nginx.conf即可复用:

http {
    # ...
    server {
        # ...
        include /var/www/magento2/nginx.conf;
    }
}

Are you sure that php is your limiting factor?您确定 php 是您的限制因素吗? In my experience it is mainly the database, which is coming up with lock wait timeouts.根据我的经验,它主要是数据库,它提出了锁定等待超时。 Adding more php processes does not help you out in that case.在这种情况下,添加更多 php 进程对您没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM