0

I have an nginx server with several servers, basically the config file looks like this:

http {
    server {
        listen              [::]:80;
        listen              80;
        server_name         DOMAIN1.com www.DOMAIN1.com;

        location ~ \.php$ {
            // ...
            fastcgi_pass            unix:/run/php/DOMAIN1-php7.3-fpm.sock;
        }

        listen [::]:443 ssl http2 ipv6only=on; 
        listen 443 ssl http2; 
        ssl_certificate /etc/letsencrypt/live/DOMAIN1/fullchain.pem; 
        ssl_certificate_key /etc/letsencrypt/live/DOMAIN1/privkey.pem; 
        include /etc/letsencrypt/options-ssl-nginx.conf; 
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
    }

    server {
        listen              [::]:80;
        listen              80;
        server_name         DOMAIN2.com www.DOMAIN2.com;

        location ~ \.php$ {
            // ...
            fastcgi_pass            unix:/run/php/DOMAIN2-php7.3-fpm.sock;
        }

        listen [::]:443 ssl http2 ipv6only=on; 
        listen 443 ssl http2; 
        ssl_certificate /etc/letsencrypt/live/DOMAIN2/fullchain.pem; 
        ssl_certificate_key /etc/letsencrypt/live/DOMAIN2/privkey.pem; 
        include /etc/letsencrypt/options-ssl-nginx.conf; 
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
    }
}

When I open DOMAIN1.com the page usually loads. But when I refresh the page several times, I will eventually get the contents of DOMAIN2.com - the same happens on DOMAIN2.com

I have 10 domains in total, and there is no "default" domain; i.e. when a wrong site is served, it's always a different one.

I can actually observe a pattern: When I make a request to a domain it works. Then I open a different browser and load a different domain. Then I refresh the first browser it serves the domain that I just opened on the second browser.

Any idea how I could debug/fix this or what configuration actually triggers this behavior?

3
  • Did you test with setting one of the domains as the "default"? Do you then still get the same issues?
    – Tommiie
    Mar 12, 2019 at 11:03
  • 1
    Nothing wrong here. It's basic load balancing.
    – Overmind
    Mar 12, 2019 at 11:09
  • This is how nginx load balancing like you did in your config works ... there is no root, no server block config for different sites, so you have the requests balanced.
    – bjoster
    Mar 12, 2019 at 13:37

1 Answer 1

1

For the record: It actually turns out, that this is no issue with nginx but with PHP.

I hadded the following line to all server blocks in nginx:

add_header X-Source-Server <DOMAIN>-$server_addr;

Here I can clearly see, that the correct nginx server block is chosen and it forwards the process correctly to the PHP FPM pool. However, the PHP pool picks the wrong Database/Docroot for some reason.

Actually, this question describes my problem:
FPM sometimes serving from wrong pool -> Possibly it's a problem caused by opcache or similar.

Following the advice I found in this blog post I could solve the issue ("why multiple PHP-FPM masters are better"). After creating a new PHP-FPM master for each domain everything is stable

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .