azuredreamfactory

Force HTTPS redirection with NGINX

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Approach A: Bitnami installations using system packages

  • Modify the /opt/bitnami/nginx/conf/server_blocks/APPNAME-server-block.conf file so that it looks like the example below. In the path above and the code example below, APPNAME is a placeholder which corresponds to the Bitnami application name. Replace this placeholder with the correct filename or path corresponding to the Bitnami application.

      server {
          listen 80 default_server;
          root /opt/bitnami/APPNAME;
          return 301 https://$host$request_uri;
      }
    
  • Modify the server section of the /opt/bitnami/nginx/conf/nginx.conf file so that it looks like this:

      server {
            listen 80;
            server_name localhost;
            return 301 https://$host$request_uri;
        }
    
  • After modifying the NGINX configuration file, open port 443 in the server firewall. Refer to the FAQ for more information.

  • Restart NGINX to apply the changes.

Approach B: Self-contained Bitnami installations

  • Modify the server section of the /opt/bitnami/nginx/conf/nginx.conf file so that it looks like this:

    server {
          listen 80;
          server_name localhost;
          return 301 https://$host$request_uri;
      }
    
  • After modifying the NGINX configuration file, open port 443 in the server firewall. Refer to the FAQ for more information.

  • Restart NGINX to apply the changes.

Last modification August 13, 2021