I have a http service that must be used by my web application during production and development. I would like to redirect all http
traffic on this service to https
unless the request comes from the lvh.me:9292
referrer (which is the URL we use during development). My naive approach was a map
as follows:
map "$scheme:$http_referrer" $redirect_https {
~/^https/ 0;
~/.*lvh\.me:9292.*/ 0;
default 1;
}
In my understand this should simply concatenate the $scheme
and the $http_referrer
and will then match against the (crude) expressions that I defined. The redirect is then written as follows:
if ($redirect_http = 1) {
return 301 https://$host$request_uri;
}
This however always results in an endless redirection cycle no matter what URL I request (with or without https, with our without a matching referrer). Am I misunderstanding something essential? Are my dumbed down regexes incorrect? Is there a better way to achieve what I am trying?
/
s from your regular expressions. That is not the correct syntax. See this document.nginx -T
to the question for the full nginx configuration.