【问题标题】:nginx no live upstreams while connecting to upstream httpsnginx 在连接到上游 https 时没有实时上游
【发布时间】:2022-03-29 18:56:28
【问题描述】:

我正在尝试将 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】:

    您尝试使用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为这个反向代理单独配置一个独立的配置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 2018-09-20
      • 2012-10-24
      • 2016-05-08
      • 2011-08-01
      相关资源
      最近更新 更多