googlenginx

Create an NGINX server block

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.

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
    
Last modification February 9, 2023