FastCGI load balance

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

upstream backend {
server weight=4000 max_fails=5 fail_timeout=5;
server 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 -log=/data/caddy.log -cpu=90% -quic

a. System environment:

Redhat 7

Thanks All,


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 :

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

    # load balancing
    lb_policy loadbalance loadbalance
    lb_try_duration 10
    lb_try_interval 5


Am i right ?

Please give me an example.


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


You mean this?


Thus your config would be:

1 Like

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