I'm trying to use a different scheme for the proxy_pass rule based on the value $host variable.
However it doesn't seem to work, here's the behavior we're observing.
If we set proxy_pass with a constant scheme like this proxy_pass https://$upstream;
everything works well, but if we try to replace the hardcoded scheme value (https) with a custom variable and then use proxy_pass $myscheme://$upstream;
Nginx seems to ignore $myscheme and tries to resolve $upstream without using a scheme, which obviously fails.
This happens even if we set the variable like this set $myscheme https;
.
Is this behavior normal? What are we doing wrong? Is there a way to use a different scheme based on the value of a variable set at runtime?
CURRENT (NOT WORKING) CONFIGURATION
Based on our tests, looks like (at the least the version we're running) Nginx is not actually replacing variables in proxy_pass
worker_processes 4;
worker_rlimit_nofile 100000;
events {
worker_connections 100000;
multi_accept on;
use epoll;
}
http {
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time';
server {
listen 443;
server_name myservername;
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/letsencrypt/live/xxx;
ssl_certificate_key /etc/letsencrypt/live/xxx;
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/json text/json text/plain application/x-javascript text/xml text/css application/xml;
access_log /var/log/nginx/access.log timed_combined;
set $myscheme https;
set $myhost myhostname;
location / {
proxy_pass $myscheme://$myhost;
}
}
}
NGINX VERSION: 1.10.3