настроенное Nginx местоположение перенаправляет обратно с кодом 302 - PullRequest
0 голосов
/ 01 апреля 2020

Я настроил Nginx как обратный прокси-сервер, указывающий на приложение Django и перенаправляющий Http на https. Теперь у меня есть задача указать местоположение / foo на другое приложение python (ajenti-панель), которое находится на http://127.0.0.1: 5480 / , но при нажатии http://127.0.0.1: 5480 / он перенаправляет на страницу входа, которая http://127.0.0.1: 5480 / view / login / normal .

Так вот мой конфиг:

 location / {
            # checks for static file, if not found proxy to app
            try_files $uri @proxy_to_app;
        }

        location @proxy_to_app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # enable this if and only if you use HTTPS
            # proxy_set_header X-Forwarded-Proto https;
            proxy_set_header Host $http_host;
            # we don't want nginx trying to do something clever with
            # redirects, we set the Host: header above already.
            proxy_redirect off;
            proxy_pass http://unix:/run/gunicorn/socket;
       }
       location = /foo {
           proxy_pass http://127.0.0.1:5480/;
           proxy_redirect ~^/(.*) $scheme://$http_host/foo/$1;
           #proxy_redirect ~^/(.*) http://$http_host:5480/$1;
           proxy_set_header HOST  $host:$server_port;
        }
    }

, когда я go до http://hostname/foo/, он переходит к https://hostname/foo/view/login/normal и Первичное Django приложение возвращает страницу, не найденную (404). Похоже, что оно работает с основным приложением django, а не с приложением, которое прослушивает порт 5480.

Я вижу с помощью curl текущий поток:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Wed, 01 Apr 2020 01:45:00 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://hostname/foo

HTTP/1.1 302 Found
Server: nginx/1.12.2
Date: Wed, 01 Apr 2020 01:45:00 GMT
Content-Length: 0
Connection: keep-alive
X-Auth-Identity:
Location: https://hostname/foo/view/login/normal
X-Worker-Name: restricted session

HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Wed, 01 Apr 2020 01:45:00 GMT
Content-Type: text/html
Content-Length: 17169
Connection: keep-alive
X-Frame-Options: SAMEORIGIN

Какой правильный способ настроить nginx, чтобы nginx знал перенаправления от http://127.0.0.1: 5480 / , должны go до http://127.0.0.1: 5480 не основное приложение?

...