简体   繁体   中英

Magento separate PHP-FPM group for admin

I run a Magento webstore with middling traffic levels, running on NGINX with 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. 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?

Yes, it's possible.

In this example, we specify a default pool, pool 1. If the URL is /admin, we will use pool 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. However, the provided Nginx configuration relies on IF directives considered slow and unsafe .

Optimal Nginx configuration for multiple PHP-FPM pools dependent on URL:

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   fastcgi_backend;

with the variable dependent on the request URL:

fastcgi_pass   $fastcgi_backend;

Modified nginx.conf.sample saved as /var/www/magento2/nginx.conf can be reused:

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

Are you sure that php is your limiting factor? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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