0

With such config a I get redirecting to google.com

server {
    listen 80;

    proxy_ssl_server_name on;
    rewrite_log on;

    location / {
        proxy_pass https://google.com;
    }
}

but if I add upstream instead of host

upstream some-backend {
    server google.com:443;
}

server {
    listen 80;

    proxy_ssl_server_name on;
    rewrite_log on;

    location / {
        proxy_pass https://some-backend;
    }
}

I am getting error from googleenter image description here

Artem
  • 101
  • 1
  • What url is showing in browser vs what you attemped? – dmr83457 Mar 26 '22 at 13:30
  • @dmr83457 I attemped http://localhost:8080/reqwrqwwerq In browser showed http://localhost:8080/reqwrqwwerq Also I used curl curl -i localhost:8080/ and this commad return google page with 404 error – Artem Mar 26 '22 at 13:35
  • I did repository with that https://github.com/ArtemMe/devops_drafts/tree/master/nginx – Artem Mar 26 '22 at 13:37

1 Answers1

0

It is because of fqdn. On the server is sent ip instead of fqdn. You can fix it with that config:

upstream google.com {
    server 10.16.1.51:443;
}

...
proxy_pass https://google.com;
proxy_ssl_server_name on;

or you can manually set headers in location section:

location / {
    proxy_pass https://some-backend;
    proxy_ssl_server_name on;
    proxy_ssl_name google.com;
    proxy_set_header Host google.com;
}
Artem
  • 101
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 06 '22 at 06:50