Elarys
Elarys

Reputation: 669

Specific fpm pool for a subdirectory

I'm trying to keep my nginx.conf simple but I'm having trouble getting a specific folder's .php files to use a different fpm than the global one.

My current configuration is

            location ~ \.php$ {
                    # Test for non-existent scripts or throw a 404 error
                    # Without this line, nginx will blindly send any request ending in .php to php-fpm
                    try_files $uri =404;
                    include /etc/nginx/fastcgi.conf;
                    fastcgi_pass unix:/run/php-fpm.socket;
            }

            location /postfixadmin/ ~ \.php$ {
                    # Test for non-existent scripts or throw a 404 error
                    # Without this line, nginx will blindly send any request ending in .php to php-fpm
                    try_files $uri =404;
                    include /etc/nginx/fastcgi.conf;
                    fastcgi_pass unix:/run/php-fpm.vmail.socket;
            }

I'm trying to get the sub folder postfixadmin (and below) to use the /run/php-fpm.vmail.socket when it comes to .php files, but otherwise globally across all other sites, use /run/php-fpm.socket. Is it possible to apply this special rule to only a single sub folder?

Unfortunately this breaks nginx and it won't load. I've tried other configs but no matter what I've tried so far just ends up either not loading or using the global socket instead.

Upvotes: 0

Views: 849

Answers (1)

SuddenHead
SuddenHead

Reputation: 1503

Try this as second location:

location ~ /postfixadmin/.*\.php$ {
...
}

Or you can try nested location:

location ~ \.php$ {
    location ^/postfixadmin/ {
        try_files $uri =404;
        include /etc/nginx/fastcgi.conf;
        fastcgi_pass unix:/run/php-fpm.vmail.socket;
    }
    try_files $uri =404;
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/run/php-fpm.socket;
}

Upvotes: 1

Related Questions