NGINX from all subdomains redirect 301 to the primary domain

Today I faced this problem, when configuring virtual hosts Nginx, after the customizations made and creating the appropriate configs, my subdomains began to refer through 301 Redirect to the main domain of the second level.

First I decided to recheck the correctness of the configuration and whether CloudFlare or SSL certificate could provoke this problem. But it turned out that the problem was not so much in the server, but in Google Chrome. It is therefore necessary to verify. Create a tab in Incognito mode and load the subdomain, if the subdomain is loaded, and if you are not in Incognito mode and pops up 301 redirect on the main domain, then the redirects were cached.

The only working method that was found is to remove the site caches in the following sequence:

  1. Go to Google Chrome developer mode
  2. Push F12
  3. At the top of the panel, you will find the vertical three dots, symbolizing the context menu.
  4. In the context menu select – Settings
  5. Network or Network tab, depending on localization
  6. Activate the tick – do not cache the page in developer mode.

After the steps are taken, try to open your subdomain with the developer panel.

These actions will remove all cached redirects, and a redirect of 301 to the main domain won’t work.