V
V
vyacheslavdmitrievich792020-04-28 08:56:49
Nginx
vyacheslavdmitrievich79, 2020-04-28 08:56:49

Why is there an endless redirect from https to http and vice versa?

Hello!
I installed the certificate using https://letsencrypt.org/.

But when entering the site, there is an endless redirection from http to https and vice versa, the error "The site stasenok.com redirected too many times." "ERR_TOO_MANY_REDIRECTS".

What could be the problem, I don’t understand the server settings well.

I am attaching a screenshot of my nginx domain config file:

5ea7c55a22e1b820775400.png

And also the config connected to it:

5ea7c57a32b5e983450586.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-04-28
@q2digger

That's why

if ($host = stasenok.com ) {
return 301 .... 
}

and it should be like this
if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }

A
Alexey Sundukov, 2020-04-28
@alekciy

  1. In the main server config, in the http {} section, write:
    http {
        map "$server_port:$host" $is_https_redirect {
            "~^80:(.+)" 1;
        }
    }

  2. server which listen 80 we remove altogether
  3. In the server that listen 443 ssl add listen 80
  4. We add there:
    if ($is_https_redirect) {
            return 301 https://$host$request_uri;
        }

  5. Let's start the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question