When the nginx proxy_pass command address is a domain name, nginx starts to report to host not found in upstream

when I want to visit the specified uri of the local website, I actually visit another website, so I use nginx as the proxy

nginx related configuration is as follows
server {

listen 80;
server_name www.example.com;
.....

location /foo/ {
    proxy_store off;
    proxy_redirect off;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Referer "no-referrer-when-downgrade";
    proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36";
    proxy_pass https://api.example.com/foo/;
}

}

nginx startup Times error host not found in upstream "api.example.com"

Apr.11,2021

resolved

location /foo/ {
    resolver 8.8.8.8; 
    set $backend "api.example.com";
    proxy_pass https://$backend;
}


there is no 'api.example.com',' in your upstream configuration. Can you post your upstream configuration

?

something like this

http {
    upstream myapp1 {
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}
Menu