This site is set up on IBM Cloud and built using Jekyll. The previous posts in the Journey to Jekyll with IBM Cloud/ Bluemix have covered bits about getting started. In the previous post in this series, we saw how to secure the site using an SSL certificate from ZeroSSL.
One of the things that we missed at that time was that the site could now be accessed using HTTP and HTTPS – we had added HTTPS but not really removed HTTP. In this post, we see how you solve that by adding the environment variable
FORCE_HTTPS and setting it to
true in the IBM Cloud Console for your application’s runtime.
These are the steps:
- Log in to the IBM Cloud Console and go to the apps page that shows the resources
- Click on your application (it should be under ‘Cloud Foundry Apps’) on that page so that you go to the dedicated page for your app
- In the menu on the left, click on the ‘Runtime’ item
- On the top of the panel that comes up, click on ‘Environment variables’
- In the section titles ‘User defined variables’ click on ‘Add’ and add a varaible called
FORCE_HTTPSwith the value
- Click on Save
- Restart the runtime by clicking on Actions (top right) and ‘Restart’
Once the restart is completed, you should find that even if you go to an HTTP URL on the website, it will automatically redirect you to the HTTPS page.
- I tried to add
force_https: trueto the
Staticfilefile which is supposed to help with the configuration but that did not take effect as we needed it to. Adding it to the Environment Variable did work.
- Documentation about the Staticfile Buildpack configuration explains this and other variables.
- The documentation about
FORCE_HTTPShas this warning: Do not enable FORCE_HTTPS if you have a proxy server or load balancer loops, for example, if you use Flexible SSL with CloudFlare.