Create an NGINX server block
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.
NGINX lets you configure server blocks for your applications, such that you can access them at (for example) http://APPNAME.example.com instead of http://example.com/APPNAME.
NOTE: Replace APPNAME in the instructions below with the actual name/path to your application.
Approach A: Bitnami installations using system packages
Follow the steps below to create an NGINX server block:
-
Create and edit the /opt/bitnami/nginx/conf/server_blocks/APPNAME-server-block.conf file and add the configuration block shown below, where APPNAME is a placeholder for your application name:
server { # Port to listen on, can also be set in IP:PORT format listen 80 default_server; root /opt/bitnami/myapp; # Catch-all server block # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names server_name _; include "/opt/bitnami/nginx/conf/bitnami/*.conf"; }
NOTE: This will be used as the default HTTP server block. If you wish to use a custom domain name, set it using the server_name directive.
-
Create and edit the /opt/bitnami/nginx/conf/server_blocks/APPNAME-https-server-block.conf file and add the configuration block shown below, where APPNAME is a placeholder for your application name:
server { # Port to listen on, can also be set in IP:PORT format listen 443 ssl default_server; root /opt/bitnami/myapp; # Catch-all server block # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names server_name _; ssl_certificate bitnami/certs/server.crt; ssl_certificate_key bitnami/certs/server.key; include "/opt/bitnami/nginx/conf/bitnami/*.conf"; }
NOTE: This will be used as the default HTTPS server block. If you wish to use a custom domain name, set it using the server_name directive.
-
Update the application configuration to reflect the revised URL if necessary. This is an application-optional step - some applications may not require it at all, while others will require specific changes. For example, if you are using WordPress, you would need to edit the /opt/bitnami/apps/wordpress/htdocs/wp-config.php file and add the following lines:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
-
Restart the NGINX server:
$ sudo /opt/bitnami/ctlscript.sh restart nginx
Approach B: Self-contained Bitnami installations
Follow the steps below to create an NGINX server block:
-
Edit the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf file and comment out the line below so that it looks like this:
#include "/opt/bitnami/apps/APPNAME/conf/nginx-prefix.conf";
-
Include the server block configuration file for your application in the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf file:
include "/opt/bitnami/apps/APPNAME/conf/nginx-vhosts.conf";
-
Update the application’s nginx-app.conf file at /opt/bitnami/apps/APPNAME/conf/nginx-app.conf with the revised application URL if necessary. For example, you might replace the line
rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
with
rewrite ^/(.+)$ /index.php?q=$1 last;
-
Update the application configuration to reflect the revised URL if necessary. This is an application-optional step - some applications may not require it at all, while others will require specific changes. For example, if you are using WordPress, you would need to edit the /opt/bitnami/apps/wordpress/htdocs/wp-config.php file and add the following lines:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
-
Restart the NGINX server:
$ sudo /opt/bitnami/ctlscript.sh restart nginx