azurelapp

Create a virtual host for a custom application

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

Understand virtual host configuration files

Bitnami installations that use system packages contain virtual host configuration files for applications in the /opt/bitnami/apache2/conf/vhosts directory.

  • The APPNAME-vhosts.conf file contains the default configuration for the HTTP virtual host. This configuration applies to applications accessed through an HTTP URL, such as http://myapp.example.com.

    NOTE: Replace the APPNAME placeholder with the identifier of the Bitnami application name, i.e. wordpress.

    <VirtualHost 127.0.0.1:80 _default_:80>
      ServerAlias *
      DocumentRoot /opt/bitnami/APPNAME
      <Directory "/opt/bitnami/APPNAME">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
      </Directory>
    </VirtualHost>
    
  • The APPNAME-https-vhosts.conf file contains the default configuration for the HTTPS virtual host. This configuration applies to applications accessed through an HTTPS URL, such as https://myapp.example.com.

    <VirtualHost 127.0.0.1:443 _default_:443>
      ServerAlias *
      DocumentRoot /opt/bitnami/APPNAME
      SSLEngine on
      SSLCertificateFile "/opt/bitnami/apache2/conf/bitnami/certs/server.crt"
      SSLCertificateKeyFile "/opt/bitnami/apache2/conf/bitnami/certs/server.key"
      <Directory "/opt/bitnami/APPNAME">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
      </Directory>
    </VirtualHost>
    

Define virtual host configuration

Bitnami installations that use system packages enable virtual hosts by default.

Approach B: Self-contained Bitnami installations

Understand virtual host configuration files

Self-contained Bitnami installations ship three configuration files in the /opt/bitnami/apps/myapp/conf/ directory: httpd-app.conf, httpd-prefix.conf and httpd-vhosts.conf.

  • The httpd-app.conf file is the main configuration file for the application. It could have different content depending on the application:

    <Directory "/opt/bitnami/apps/myapp/htdocs">
        Options +MultiViews
        AllowOverride None
        <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
        Require all granted
        </IfVersion>
    </Directory>
    
    Include /opt/bitnami/apps/myapp/conf/htaccess.conf
    

    For security and performance reasons, it is advisable to not set AllowOverride All to anything other than None (refer to this Apache note for more information). Bitnami applications store this configuration in the /opt/bitnami/apps/myapp/conf/htaccess.conf file (more information).

  • The httpd-prefix.conf file ships the default configuration for the applications in “prefix” mode, such that the application can be accessed at (for example) http://example.com/myapp.

    Alias /myapp/ "/opt/bitnami/apps/myapp/htdocs/"
    Alias /myapp "/opt/bitnami/apps/myapp/htdocs"
    
    Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
    
  • The httpd-vhosts.conf file contains the default configuration for virtual hosts, for applications to be accessed at (for example) http://myapp.example.com.

    <VirtualHost *:8080>
      ServerName myapp.example.com
      DocumentRoot "/opt/bitnami/apps/myapp/htdocs"
      Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
    </VirtualHost>
    
    <VirtualHost *:8444>
      ServerName myapp.example.com
      DocumentRoot "/opt/bitnami/apps/myapp/htdocs"
      SSLEngine on
      SSLCertificateFile "/opt/bitnami/apps/myapp/conf/certs/server.crt"
      SSLCertificateKeyFile "/opt/bitnami/apps/myapp/conf/certs/server.key"
      Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
    </VirtualHost>
    

Define virtual host configuration

To configure your application to use a virtual host instead of the prefix URL, make these changes:

  • Delete the following line in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

    Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
    
  • Add a new link in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf file:

    Include "/opt/bitnami/apps/myapp/conf/httpd-vhosts.conf"
    
    • Some applications require further changes in configuration files or the database. Please check the exact changes in the application’s documentation.

NOTE: After modifying the Apache configuration files, restart Apache to apply the changes.

Last modification June 9, 2020