FastCGI load balance

How can i load balance my fastcgi to backend for example like nginx

upstream backend {
server 127.0.0.1:9000 weight=4000 max_fails=5 fail_timeout=5;
server 127.0.0.1:9001 weight=4000 max_fails=5 fail_timeout=5;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass backend;
}

1. My Caddy version (1.0.3):

2. How I run Caddy:

/usr/local/bin/caddy -conf=caddy.file -email=entuy@gmail.com -log=/data/caddy.log -cpu=90% -quic

a. System environment:

Redhat 7

Thanks All,

Rino

Caddy 2 can do this :slight_smile:

You can use the php_fastcgi directive, which takes the same syntax as the reverse_proxy directive:

Notice how you can define multiple backends and load balancing policies and health checks.

Please try it out!

Hi Matt,

Thanks for the reply, then if my case i have 2 node php-fpm server let say :

127.0.0.1:9000
127.0.0.1:9001

then the config will be :

matcher phpFiles {
    path *.php
}
reverse_proxy match:phpFiles php-fpm:9000 {
    transport fastcgi {
        split .php
    }
}

reverse_proxy phpFiles  backend {
    # backends
    to 127.0.0.1:9000, 127.0.0.1:9001

    # load balancing
    lb_policy loadbalance loadbalance
    lb_try_duration 10
    lb_try_interval 5

}


Am i right ?

Please give me an example.

Thanks

Why not just use the php_fastcgi directive? Then it’s just one line or two.

Because it’s not written in the doc :wink:

...
reverse_proxy match:phpFiles php-fpm:9000 {
 transport fastcgi {
     split .php
 }
}

@al-caddyserver

You mean this?

:slight_smile:

Thus your config would be:

php_fastcgi 127.0.0.1:9000 127.0.0.1:9001
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.