azureroutesnginx-configazure-cdnmicrosoft-cdn

Redirect Loop with Azure CDN


I have domains example.com & www.example.com

The www. subdomain is attached to an Azure CDN, using Microsoft CDN Classic. I tried to map the non www. to the CDN with the following NGINX config:

server 
{
    listen 8080;
    listen [::]:8080;
    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

The intent here is to redirect everything from https://example.com to https://www.example.com.

But it results in a site-wide 301 "Too many redirects". However, when i turn off the CDN (e.g. disassociate the www. domain), that config works just fine.

I tried to add a custom non-shared SSL certificate to example.com but that didnt fix it.

How can i make this work with the CDN?


Solution

  • I was not able to fix this at its root via NGINX config or the Azure interface but managed with a workaround:

    I unregistered the non www. domain from Azure and pointed it to an alternate webspace which then redirects to the www. domain of the CDN. This way www. and non www. are working properly with the CDN. The workaround is agreeable ugly but not noticeable to a user.