NGINX – return 301 keeps redirecting to HTTP instead of HTTPS

301-redirecthttpsnginx

I have the following configuration:

server{ 
  ssl on;
  listen 443 ssl;
  ...
  location = / {
    return 301 https://$host/appName;
  }
  location = /appName {
    ...
    proxy_pass $some_internal_server;
    ...
  }
}

When I type in a browser https://my_url I'm redirected to http://my_url/appName instead of https://my_url/appName

How can I fix this?

Best Answer

The best way to fix a 301 is another 301.

301 is browser cache, add a 301 on http back to https