Search code examples
sslhttp-headerscloud-foundryswisscomdev

How to force https on Swisscom cloud foundry with Staticfile Buildpack (FORCE_HTTPS)


I configured the env option FORCE_HTTPS = true as suggested in the documentation:

My manifext.yml

env:
  APP_ENV: production
  FORCE_HTTPS: true

However, when I open the website with http I do not get redirected to https.

I use a custom nginx.conf file

The setting was applied


Solution

  • I added the following line to my custom '/nginx.conf' file.

        location / {
            <% if ENV["FORCE_HTTPS"] %>
                if ($http_x_forwarded_proto != "https") {
                    return 301 https://$host$request_uri;
                }
            <% end %>
            ...
        }