0

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?

3
  • Do you actually mean the referrer (which is often missing, especially when you start mixing http and https), or do you mean the host? Or, if you are talking about a webservice on one server queried from pages served from another host?
    – jcaron
    Apr 14, 2021 at 11:04
  • You should remove the /s from your regular expressions. That is not the correct syntax. See this document. Apr 14, 2021 at 12:08
  • Please add output of nginx -T to the question for the full nginx configuration. Apr 14, 2021 at 16:35

0

You must log in to answer this question.

Browse other questions tagged .