#1020 closed enhancement (wontfix)
Allow proxy_http_version to use variables
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | nginx-module | Version: | 1.6.x |
| Keywords: | proxy proxy_pass proxy_http_version | Cc: | |
| uname -a: | Linux testing-946235561-bc338 4.2.2-coreos-r2 #2 SMP Fri Jan 22 06:06:09 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux | ||
| nginx -V: |
nginx version: nginx/1.6.2
TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.6.2/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.6.2/debian/modules/nginx-dav-ext-module --add-module=/build/buildd/nginx-1.6.2/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.6.2/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.6.2/debian/modules/ngx_http_substitutions_filter_module |
||
Description
I would like to conditionally set the proxy_http_version such that the requested HTTP version is used for the upstream request instead of locking it down to 1.0 or 1.1. My attempts at doing this have failed because proxy_http_version does not allow you to use a variable to set its value. Here was what I thought was the intuitive approach to this:
events {}
http {
map $http_version $proxy_http_version {
default 1.0;
"1.1" 1.1;
}
proxy_http_version $proxy_http_version;
server {
listen 9999 default_server;
return 444;
}
}
daemon on;
Of course, that results in the following error: nginx: [warn] invalid value "$proxy_http_version" in /etc/nginx/nginx.conf:8, which is because the variable is a string but proxy_http_version If proxy_http_version was allowed to be set via a variable value, I could use the same HTTP version of the request for the upstream request.
I also tried a different version using if but proxy_http_version isn't allowed in an if either so both attempts at solving this have failed. I worried about setting proxy_http_version to 1.1 always to work around the known issues I'm facing (WebSockets and streaming APIs) but maybe that's the only solution?

Just use
proxy_http_version 1.1. Most modern backends handle this just fine, and there are no known negative effects. If you want to limitproxy_http_version 1.1to minimal set of requests, use appropriatelocationfor URIs where you need HTTP/1.1.If really needed,
proxy_http_versioncan be used conditionally by using different locations and switching them usingif+return+error_page. Though this is not something needed in this particular case.