1

I'm using nginx 1.14.2 as a reverse proxy with following configuration

server {
        listen xxxxxxx:80;
        server_name xxxxxx;
        proxy_intercept_errors on;

        location /nodejs {
                proxy_pass https://nodejs.org;
                proxy_cache cache;
                proxy_cache_valid 200 301 302 30d;
                proxy_cache_valid 404 1m;
                expires 30d;
                proxy_ssl_server_name on;
                proxy_cache_use_stale error timeout invalid_header updating;
        }
}

I'm getting 502 Bad gateway on browser: enter image description here In nginx errors logs, i found following line:

2020/12/10 11:23:23 [error] 16462#16462: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.23.46:443/nodejs", host: "xxxxxxxx"

But since there is a proxy in the backend, the URL with IP address is blocked. Have you an idea how to force nginx to use domainname in place of IP address in upstream

Thanks.

Edit: I added following line to the proxy_pass config:

rewrite /nodejs/(.*) /dist  break;

Now the error log is like this :

2020/12/10 12:22:37 [error] 16541#16541: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.22.46:443/dist", host: "xxxxxxx"
2
  • The timeout rather suggest a firewall issue, not a problem with IP vs hostname. Dec 10 '20 at 10:52
  • I pretty sure there is no firewall, since with wget/curl the website is reachable
    – aniskh
    Dec 10 '20 at 12:51
1

You need this directive: proxy_ssl_server_name on;
The default is off.

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name

1
  • Thanks @unNamed , i added this directive, but it didn't solve my issue, finally i managed to solve the issue by tuning the rewrite directive: rewrite nodejs/(.*)$ https://nodejs.org/dist/$1 break; rewrite nodejs https://nodejs.org/dist break;
    – aniskh
    Jan 7 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.