Docker Community Forums

Share and learn in the Docker community.

Question loadbalance PHP-FPM with NGINX

Hello,

First of all i want to say im new to Docker.

Docker Version: 19.03.12-ce, running on Manjaro

Im using docker local now to try how it works, but want to use it in the future on my server for future projects.
I did see it works great with load balancing, i can just scale my nginx containers that are behind 1 nginx that i use as proxy/loadbalancer and it works great.

I tried the same for my PHP, by using this in my nginx conf

location ~ \.php$ {
    try_files $uri =404;

    # Increase valid time in production
    resolver 127.0.0.11 valid=5s;
    set $upstream php_dev;
    # loadbalance PHP

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass $upstream:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

It ‘works’, it does load the pages without problems.
but in the logs i always see php_dev_1 while there are more php_dev_* containers running when i use ‘docker ps’

Second question (Not really important, just hoping to get some keywords so i know what to look for):
How could i scale my MySQL database ?
For NGINX/PHP the files dont really change that often (I use volumes so i can change it in all /var/www/html folders), but with MySQL it has to sync or something.

Find your php-fpm configuration (default source install location is /usr/local/etc/php-fpm.conf) and make sure that listen.allowed_clients is set to allow the IP of your Nginx box.

If this doesn’t fix it then check your Nginx error log for further details.

Thanks Lewish,
It seems that listen.allowed_clients is commented, wich means its accepting from all sources it says above it.

It does find the first php container (Its in the logs), but never uses another php container no mather how many i create.

Cant seem to find the logs for Nginx, even while it is set in the conf.

Edit:
Looks like it doesnt see the other php_dev containers.

nslookup on the nginx container that is used as a loadbalancer:
root@debfaaaaf82c:/# nslookup php_dev
Server: 127.0.0.11
Address: 127.0.0.11#53

Non-authoritative answer:
Name: php_dev
Address: 172.25.0.9
Name: php_dev
Address: 172.25.0.6
Name: php_dev
Address: 172.25.0.8
Name: php_dev
Address: 172.25.0.7
Name: php_dev
Address: 172.25.0.5

nslookup on 1 off the nginx containers (That are even made after the php_dev containers where running)
root@b27e17382a9d:/# nslookup php_dev
Server: 127.0.0.11
Address: 127.0.0.11#53

Non-authoritative answer:
Name: php_dev
Address: 172.25.0.5

For some reason the loadbalancer can see them, but the nginx containers cant?

Think this is the reason its not working.
Both are stock debian 10 buster nginx images, with just some nginx configs changed for the specific usage off the containers, loadbalance/run php files on php-fpm containers