1

I have five websites and I have three servers, all running nginx.

  1. Primary server
  2. Load balancer
  3. Failover server

Each website has it's own primary server but they all share the same failover server. My load balancer is set to send all traffic to each website's primary server. Only if that primary server goes down will the load balancer send traffic to the failover server.

For each website, I have a separate nginx config file on the load balancer that is similar to this:

upstream website {
        server 1.2.3.4 fail_timeout=3s max_fails=3 weight=10000;
        server 4.3.2.1;
}

server {
        listen 80;
        server_name www.websitename.com;
        client_max_body_size 150M;
        location / {
                proxy_pass http://website;
        }
}


server {
        listen 80;
        server_name websitename.com;
        client_max_body_size 150M;
        location / {
                proxy_pass http://website;
        }
}

With that config file, everything works just fine. All traffic is sent to the primary server, if the primary server goes down, the traffic will be sent to the failover server.

The problem comes with the failover server. I have five different websites on the failover server, all with their own separate nginx config file in the sites-available directory. The problem is, when traffic is sent to the failover server, nginx is showing the first available config file and the associated website, not the correct website.

Each website config file on the failover server looks like the config file below. Of course, each one has a different URL and root directory but that is the only difference. In this case, I have matched the example config file to be associated with the example load balancer config file:

server {                                                         
        listen 80;                                               
        listen [::]:80;                                          

        root /usr/share/nginx/html/websitename;                   

        index index.php;                                         

        server_name websitename.com;                 

        location / {                                             
                try_files $uri $uri/ /index.php?$args;           
        }                                                        

        location ~ \.php$ {                                      
                try_files $uri =404;                             
                fastcgi_split_path_info ^(.+\.php)(/.+)$;        
                fastcgi_pass unix:/var/run/php5-fpm.sock;        
                fastcgi_index index.php;                         
                include fastcgi_params;                          
        }
}

Also, I am not sure if this matters but the DNS A record for the website is set to point to the load balancer.

I am quite certain the problem lies with the fail over website config files but I don't know what is wrong. I would appreciate any help, thanks.

0

It looks like I found out the answer to this.

I needed to add the line proxy_set_header Host $host; right under the proxy_pass lines on my load balancer config files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.