Назад | Перейти на главную страницу

Nginx err too many redirects error после настройки ssl

Я гуглил последние 6 часов и не нашел, что не так с моим nginx.conf. Моя установка - django> gunicorn> nginx. мой nginx.conf ниже (из-за многих испытаний немного грязный):

upstream app_server {
    server unix:/home/django/gunicorn.socket fail_timeout=0;
}
server {
    listen 80 ;
    listen [::]:80  ipv6only=on;
    server_name comparebet.co.ke www.comparebet.co.ke;

    return 301 https://$server_name$request_uri;

    client_max_body_size 4G;
    keepalive_timeout 5;

    location /media  {
        alias /home/django/django_project/django_project/media;
    }

    access_log /var/log/access.log;
    error_log /var/log/error.log;
}

server  {
    listen 443;
    ssl on;
    listen [::]:443 ssl http2;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

    server_name comparebet.co.ke;

    root /usr/share/nginx/html;
    index index.html index.htm;

    location /static {
        alias /home/django/django_project/django_project/static;
    }

    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://comparebet.co.ke;
    }

    location ~ /.well-known {
        allow all;
    }

    access_log /var/log/access.log;
    error_log /var/log/error.log;
}

Буду признателен за любую помощь. Спасибо

Отредактировано, чтобы включить заголовки ответов curl

* Rebuilt URL to: comparebet.co.ke/
*   Trying 178.62.11.22...
* Connected to comparebet.co.ke (178.62.11.22) port 80 (#0)
> GET / HTTP/1.1
> Host: comparebet.co.ke
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.10.0 (Ubuntu)
< Date: Wed, 22 Mar 2017 00:18:58 GMT
< Content-Type: text/html
< Content-Length: 194
< Connection: keep-alive
< Location: https://comparebet.co.ke/
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>
* Connection #0 to host comparebet.co.ke left intact

Основная проблема заключается в том, что когда к домену обращается браузер Chrome, он возвращает «ERR: TOO MANY REDIRECTS». Это то, что я хочу решить

Ваш https-сервер содержит эту строку (отрывок). Это говорит ему отправлять любые запросы, идущие на сайт https, обратно на сайт http.

location / {
    proxy_pass http://comparebet.co.ke;
}

Ваш http-сервер содержит эти строки, перенаправляя запросы обратно на https-сайт.

server_name comparebet.co.ke www.comparebet.co.ke;
return 301 https://$server_name$request_uri;

Nginx делает именно то, что вы ему сказали, а именно создает цикл перенаправления. Решение зависит от того, что вы пытаетесь сделать.