0

Our current nginx setup handles http/https with a solution similar to the one specified in this answer

nginx.conf

http {
    upstream backend {
        server backend.com
    }
    upstream backend_ssl {
        server backend.com:443
    }
}

sites-available/domain.conf

server {
    listen 80;
    server_name www.domain.com
    location /a/update {
        proxy_pass http://backend;
    }
}

sites-available/domain_ssl.conf

server {
    listen 443 ssl;
    server_name www.domain.com
    location /a/update {
        proxy_pass https://backend_ssl;
    }
}

I'd like to modify this to use the solution mentioned in the official nginx docs for using a single http/https server block. How do I do this in the above scenario as even though the location block url is same, the proxy_pass directive parameter differs for http and https.

livinston
  • 105

1 Answers1

1

Use the $scheme variable.

server {
    listen 80;
    listen 443 ssl;
    server_name www.domain.com
    location /a/update {
        proxy_pass $scheme://backend;
    }
}