nginx нет прямых трансляций при подключении к восходящему https - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь прокси-запросы api к удаленному серверу api (https://api.domain.com). Это мой nginx config

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

        server_name dev.domain.com;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_pass http://127.0.0.1:8080;
        }

        location /api/ {
                proxy_pass https://api.domain.com;

        }

Но я получил ошибку

no live upstreams while connecting to upstream, client: x.x.x.x, server: dev.domain.com, request: "GET /api/current_ip HTTP/1.1", upstream: "https://api.domain.com/api/current_ip", host: "dev.domain.com", referrer: "https://dev.domain.com/api/current_ip"

Я не понимаю, что пропущено в моей конфигурации.

1 Ответ

0 голосов
/ 22 февраля 2020

Вы пытаетесь запросить URL, используя http и пароль прокси https, вам нужно будет добавить конфигурацию SSL, когда вы закончите, вы должны поставить location /api/ перед location /

server {
        listen 80 default_server;       # to remove, You will need to setup SSL
        listen [::]:80 default_server;  # to remove, You will need to setup SSL

        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_....
        ...

        server_name dev.domain.com;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        location /api/ {      ## Put this first
                proxy_pass https://api.domain.com;
        }

        location / {          ## Put this always at the end (is like a *wilcard)
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_pass http://127.0.0.1:8080;
        }
}

Если вы хотите отменить прокси-сервер с использованием TLS, вы должны также предоставить TLS.

В какой-то момент будет лучше использовать автономную конфигурацию только для этого обратного прокси с https

...