nginx在连接到上游https时没有实时上游

时间:2020-02-18 07:20:21

标签: nginx reverse-proxy proxypass

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

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

1 个答案:

答案 0 :(得分:0)

您尝试使用http和pass pass 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的此反向代理设置一个独立的配置

相关问题