nginx在连接到上游https时没有活动的上游

问题描述 投票:0回答:1

我正在尝试将api请求代理到远程api服务器(https://api.domain.com)那是我的nginx配置

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"

我不知道我的配置中缺少什么。

nginx reverse-proxy proxypass
1个回答
0
投票

[您尝试使用http和代理传递https请求url,则需要添加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的此反向代理提供独立的配置>

© www.soinside.com 2019 - 2024. All rights reserved.