title: Nginx redirects inconsistent across browsers
body: <p>I have a top-level domain. Let's call it <code>example.com</code>. I also have three subdomains: <code>www.example.com</code>, <code>app.example.com</code> and <code>static.app.example.com</code>.</p>
  
  <p>I want <code>example.com</code> to redirect to <code>www.example.com</code>.
  I also want all http traffic to redirect to https while preserving the domain and the path.</p>
  
  <p>These are my nginx config files (sorry, it's a bit long):</p>
  
  <pre><code>###############  app.example.com ###################
  
  server {
      listen 80;
      listen [::]:80;
      server_name app.example.com;
      return 301 https://app.example.com$request_uri;
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      include snippets/ssl-example.com.conf;
      include snippets/ssl-params.conf;
  
      server_name app.example.com;
  
      location / {
          proxy_pass http://localhost:5000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
      }
  
      location /assets {
          alias /var/www/exampleapp/dist/public;
      }
  
      location /.well-known {
          alias /var/www/example/.well-known;
      }
  }
  
  ###############  static.app.example.com ###################
  
  server {
      listen 80;
      listen [::]:80;
      server_name static.app.example.com;
      return 301 https://static.app.example.com$request_uri;
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      include snippets/ssl-example.com.conf;
      include snippets/ssl-params.conf;
  
      server_name static.app.example.com;
  
      location / {
          alias /var/www/exampleapp/public/;
      }
  
      location /.well-known {
          alias /var/www/example/.well-known;
      }
  }
  
  ###############  www.example.com &amp; example.com ###################
  
  server {
      listen 80;
      listen [::]:80;
      server_name www.example.com;
      return 301 https://www.example.com$request_uri;
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      include snippets/ssl-example.com.conf;
      include snippets/ssl-params.conf;
  
      server_name example.com;
      return 301 $scheme://www.example.com$request_uri;
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      include snippets/ssl-example.com.conf;
      include snippets/ssl-params.conf;
  
      server_name www.example.com;
  
      location / {
          proxy_pass http://localhost:5500;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
      }
  
      location /assets {
          alias /var/www/example/dist/public;
      }
  
      location /.well-known {
          alias /var/www/example/.well-known;
      }
  }
  </code></pre>
  
  <p>Now here's the weird part. This works perfectly fine on desktop chrome and firefox. But on mobile chrome and edge, it does something strange. It redirects from <code>example.com</code> to <code>app.example.com</code>. I can't figure out what it is. I've tried clearing the browser cache and playing with nginx settings but nothing helps.</p>