"redirected you too many times" error when trying NGINX Load Balancer between two Wordpress + LEMP Stack servers

November 5, 2019 569 views
LEMP Load Balancing Nginx WordPress Ubuntu 16.04

Hey there. I’m new at NGINX. I’ve a problem about Load Balancing for my local websites. I create three servers on different three Ubuntu 16.04 core servers.

I need to configure this 3 servers for, when client try to reach “https://tac.local” from browser, load balancer take the request and make Load balance between my two webserver. I can use round robin type btw.

  1. Load Balancer NGINX (Round Robin) - 192.168.56.8
  2. Web Server1 (LEMP Stack, Wordpress with self signed SSL) - 192.168.56.12
  3. Web Server2 (LEMP Stack, Wordpress with self signed SSL) - 192.168.56.13

Here my config files;

  1. Load Balancer (/etc/nginx/conf.d/load-balancer.conf)
upstream backend {
    server 192.168.56.8;
    server 192.168.56.12;
    server 192.168.56.13;
}

server {
   listen 80;
   listen 443 ssl;
   server_name tac.local;

   include snippets/self-signed.conf;
   include snippets/ssl-params.conf;

   location / {
      proxy_pass                   http://backend;
      proxy_set_header        Host                            $host;
      proxy_set_header        X-Real-IP                    $remote_addr;
      proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto   $scheme;
   }
}
  1. Web Server1 and Web Server2 same config files - different Ubuntu 16.04 (/etc/nginx/sites-available/default)
server {
        listen 80;
        listen [::]:80;

        server_name $host;
        return 301 https://$host$request_uri;

}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name tac.local;

        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;

        root /var/www/$host/public;

        index index.php index.html index.htm index.nginx-debian.html;

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
    }

       location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

When i try to reach “https://tac.local” from Chrome, it’s saying;
This page isn’t working
tac.local redirected you too many times.
Try clearing your cookies.
ERRTOOMANY_REDIRECTS

Can you help me please?

2 Answers

Hello,

I would recommend trying to add the following right after the opening php tag in your wp-config.php file:

if ( 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
  $_SERVER['HTTPS'] = 'on';
  $_SERVER['SERVER_PORT'] = '443';
}

Then clear the cache of your browser and test it again.

Let me know how it goes.
Regards,
Bobby

Have another answer? Share your knowledge.