Bitnami Nginx Installer

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.
NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

Description

Nginx is a popular web server that can also be used as a reverse proxy, load balancer, and http cache.

First steps with the Bitnami Nginx Stack

Welcome to your new Bitnami application! Here are a few questions (and answers!) you might need when first starting with your application.

What are the system requirements?

Before you download and install your application, check that your system meets these requirements.

How do I install the Bitnami Nginx Stack?

Windows, OS X and Linux installer
  • Download the executable file for the Bitnami Nginx Stack from the Bitnami website.

  • Run the downloaded file:

    • On Linux, give the installer executable permissions and run the installation file in the console.
    • On other platforms, double-click the installer and follow the instructions shown.

Check the FAQ for instructions on how to download and install a Bitnami Stack for more details.

The application will be installed to the following default directories:

Operating System Directory
Windows C:\Bitnami\APPNAME-VERSION
Mac OS X /Applications/APPNAME-VERSION
Linux /opt/APPNAME-VERSION (running as root user)
OS X VM
  • Download the OS X VM file for the Bitnami Nginx Stack from the Bitnami website.
  • Begin the installation process by double-clicking the image file and dragging the WordPress OS X VM icon to the Applications folder.
  • Launch the VM by double-clicking the icon in the Applications folder.

What credentials do I need?

You need application credentials, consisting of a password. This will allow you to log in to the services of the Bitnami stack.

What is the administrator password?

  • For Windows, Linux and OS X installers, the password was configured by you when you first installed the application.
  • For OS X VMs, the password can be obtained by clicking the Bitnami badge at the bottom right corner of the application welcome page.

How to start or stop the services?

Linux

Bitnami native installers include a graphical tool to manage services. This tool is named manager-linux-x64.run on Linux and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

      $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql, postgresql or apache:

      $ sudo installdir/ctlscript.sh restart mysql
      $ sudo installdir/ctlscript.sh restart postgresql
      $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

      $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

Mac OS X

Bitnami native installers include a graphical tool to manage services. This tool is named manager-osx on Mac OS X and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

    $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql or apache:

     $ sudo installdir/ctlscript.sh restart mysql
     $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

     $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

NOTE: If you are using the stack manager for Mac OS X-VM, please check the following blog post to learn how to manage services from its graphical tool.

Windows

Bitnami native installers include a graphical tool to manage services. This tool is named manager-windows.exe on Windows and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The Windows native installer creates shortcuts to start and stop services created in the Start Menu, under "Programs -> Bitnami APPNAME Stack -> Bitnami Service". Servers can also be managed from the Windows "Services" control panel. Services are named using the format APPNAMESERVICENAME, where APPNAME is a placeholder for the application name and SERVICENAME is a placeholder for the service name. For example, the native installer for the Bitnami WordPress Stack installs services named wordpressApache and wordpressMySQL.

These services will be automatically started during boot. To modify this behaviour, refer to the section on disabling services on Windows.

Which components are installed with the Bitnami Nginx Stack?

The Bitnami Nginx Stack ships the components listed below. If you want to know which specific version of each component is bundled in the stack you are downloading, check the README.txt file on the download page or in the stack installation directory. You can also find more information about each component using the links below.

Main components

Dependencies and additional components

  • Varnish proxy cache server
  • ImageMagick tool
  • SQLite database
  • XDebug module
  • Memcache module
  • APC module
  • GD library
  • OpenSSL library
  • CURL library
  • OpenLDAP library
  • PEAR and PECL package manager tools

How can I get started with Nginx?

Once the deployment finishes, you can access the welcome page from your browser: http://localhost/.

To get started, we suggest the following steps:

Step 1: Deploy a custom PHP application

The main directory to deploy your PHP application is installdir/nginx/html/. You can copy your PHP application files to that directory and access the application via your browser. If you do not have a PHP application yet, we suggest deploying the PHP info example.

Do you have issues trying to connect to your server? Check our FAQ.

Step 2: Create a virtual host for your application

Nginx lets you configure virtual hosts for your applications, such that you can access them at (for example) http://APPNAME.example.com instead of http://example.com/APPNAME.

For information on how to do this, refer to these instructions.

Step 3: Access phpMyAdmin

phpMyAdmin is a PHP-based application intended to handle the administration of MySQL over the Web. For security reasons, this application is not accessible via web by default. To access it from a remote system, we recommend creating a SSH tunnel that routes requests to the Apache Web server from 127.0.0.1.

Find more information on how to access phpMyAdmin.

How to find the MySQL database credentials?

How to connect to the MySQL database?

You can connect to the MySQL database from the same computer where it is installed with the mysql client tool.

$ mysql -u root -p

You will be prompted to enter the root user password. This is the same as the application password.

How to connect to Nginx from a different machine?

For security reasons, the Nginx ports in this solution cannot be accessed over a public IP address. To connect to Nginx from a different machine, you must open port 80, 443 for remote access. Refer to the FAQ for more information on this.

IMPORTANT: Bitnami Native Installers do not modify the firewall configuration of your computer, therefore the Nginx ports could be open which is a significant security risk. You are strongly advised to close the Nginx ports (refer to the FAQ for more information on this).

How to access phpMyAdmin?

You should be able to access phpMyAdmin directly, by browsing to http://127.0.0.1/phpmyadmin.

The username is root for phpMyAdmin, and the password is the one specified by you during the installation process.

How to reset the MariaDB root password?

Please note that depending on the version you have installed, you may find the MariaDB files at installdir/mysql

If you don't remember your MariaDB root password, you can follow the steps below to reset it to a new value:

  • Create a file in /home/bitnami/mysql-init with the content shown below (replace NEW_PASSWORD with the password you wish to use):

     UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
     FLUSH PRIVILEGES;
    
  • Stop the MariaDB server:

     $ sudo installdir/ctlscript.sh stop mariadb
    
  • Start MariaDB with the following command:

     $ sudo installdir/mariadb/bin/mysqld_safe --defaults-file=installdir/mariadb/my.cnf --pid-file=installdir/mariadb/data/mysqld.pid --init-file=/home/bitnami/mysql-init 2> /dev/null &
    
  • Restart the MariaDB server:

     $ sudo installdir/ctlscript.sh restart mariadb
    
  • Remove the init script

     $ rm /home/bitnami/mysql-init
    

How to change the MariaDB root password?

You can modify the MariaDB password using the following command at the shell prompt:

$ installdir/mariadb/bin/mysqladmin -p -u root password NEW_PASSWORD

How to create an SSL certificate?

You can create your own SSL certificate with the OpenSSL binary. A certificate request can then be sent to a certificate authority (CA) to get it signed into a certificate, or if you have your own certificate authority, you may sign it yourself, or you can use a self-signed certificate (because you just want a test certificate or because you are setting up your own CA).

NOTE: In the following steps, replace the APPNAME placeholder with the name of your application directory.
  • Generate a new private key:

     $ sudo openssl genrsa -out installdir/apps/APPNAME/conf/certs/server.key 2048
    
  • Create a certificate:

     $ sudo openssl req -new -key installdir/apps/APPNAME/conf/certs/server.key -out installdir/apps/APPNAME/conf/certs/cert.csr
    
    IMPORTANT: Enter the server domain name when the above command asks for the "Common Name".
  • Send cert.csr to the certificate authority. When the certificate authority completes their checks (and probably received payment from you), they will hand over your new certificate to you.

  • Until the certificate is received, create a temporary self-signed certificate:

     $ sudo openssl x509 -in installdir/apps/APPNAME/conf/certs/cert.csr -out installdir/apps/APPNAME/conf/certs/server.crt -req -signkey installdir/apps/APPNAME/conf/certs/server.key -days 365
    
  • Back up your private key in a safe location after generating a password-protected version as follows:

     $ sudo openssl rsa -des3 -in installdir/apps/APPNAME/conf/certs/server.key -out privkey.pem
    

    Note that if you use this encrypted key in the configuration file, Nginx won't be able to start. Regenerate the key without password protection from this file as follows:

     $ sudo openssl rsa -in privkey.pem -out installdir/apps/APPNAME/conf/certs/server.key
    

Find more information about certificates at http://www.openssl.org.

How to enable HTTPS support with SSL certificates?

TIP: If you wish to use a Let's Encrypt certificate, you will find specific instructions for enabling HTTPS support with Let's Encrypt SSL certificates in our Let's Encrypt guide.
NOTE: The steps below assume that you are using a custom domain name and that you have already configured the custom domain name to point to your cloud server.

Bitnami images come with SSL support already pre-configured and with a dummy certificate in place. Although this dummy certificate is fine for testing and development purposes, you will usually want to use a valid SSL certificate for production use. You can either generate this on your own (explained here) or you can purchase one from a commercial certificate authority.

Once you obtain the certificate and certificate key files, you will need to update your server to use them. Follow these steps to activate SSL support:

  • Use the table below to identify the correct locations for your certificate and configuration files.

    Variable Value
    Current application URL https://[custom-domain]/
      Example: https://my-domain.com/ or https://my-domain.com/appname
    Nginx configuration file installdir/nginx/conf/bitnami/bitnami.conf
    Certificate file installdir/nginx/conf/server.crt
    Certificate key file installdir/nginx/conf/server.key
  • Copy your SSL certificate and certificate key file to the specified locations.

  • Once you have copied all the server certificate files, you may make them readable by the root user only with the following commands:

     $ sudo chown root:root installdir/nginx/conf/server*
    
     $ sudo chmod 600 installdir/nginx/conf/server*
    
  • Open port 443 in the server firewall. Refer to the FAQ for more information.

  • Restart the Nginx server.

     $ sudo installdir/ctlscript.sh restart nginx
    

You should now be able to access your application using an HTTPS URL.

How to create a Virtual Host in the Bitnami Nginx Stack?

Nginx lets you configure virtual hosts 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.
  • Edit the installdir/nginx/conf/bitnami/bitnami-apps-prefix.conf file and comment out the line below so that it looks like this:

    #include "installdir/apps/APPNAME/conf/nginx-prefix.conf";
    
  • Include the virtual host configuration file for your application in the installdir/nginx/conf/bitnami/bitnami-apps-vhosts.conf file:

     include "installdir/apps/APPNAME/conf/nginx-vhosts.conf";
    
  • Update the application's nginx-app.conf file at installdir/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-specific step and different applications will require different changes. For example, if you are using WordPress, you would need to edit the installdir/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 installdir/ctlscript.sh restart nginx
    

How to increase the upload size limit in the Bitnami Nginx Stack?

Add the client_max_body_size directive inside the http { } section of the installdir/nginx/conf/nginx.conf file. For instance, to increase your upload size to 20MB, add the following line:

client_max_body_size 20m;

Remember to restart the Nginx server for your changes to take effect.

$ sudo installdir/ctlscript.sh restart nginx

To increase the upload file size limit for PHP, follow the steps described here.

How to create a password to protect access to an application?

To configure Nginx to request a username and password when accessing your application, follow these steps:

  • At the console, type the following commands. Remember to replace APPNAME, USERNAME and PASSWORD with your application name, desired username and desired password respectively.

      $ sudo apt-get update
      $ sudo apt-get install apache2-utils
      $ cd installdir/APPNAME/conf/
      $ sudo htpasswd -cb users USERNAME PASSWORD
    
  • Edit the installdir/apps/APPNAME/conf/nginx-app.conf file and update the default location block as shown below:

      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_read_timeout 300;
          fastcgi_pass unix:installdir/php/var/run/www.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $request_filename;
          include fastcgi_params;
          auth_basic "Restricted Area";
          auth_basic_user_file installdir/APPNAME/conf/users;
      }
    
    NOTE: If you don't wish to protect the entire application, but only a sub-URL, create a new location block as shown above only for the sub-URL you wish to protect.
  • Restart the Nginx server:

     $ sudo installdir/ctlscript.sh restart nginx
    

When accessing the application, you will see an authentication popup window. Enter the username and password defined in the first step:

To change the password later, run the htpasswd utility without the -c switch:

$ sudo htpasswd installdir/users USERNAME

How to force HTTPS redirection with Nginx?

Modify the installdir/nginx/conf/bitnami/bitnami.conf file so that it looks like this:

server {
      listen 80;
      server_name localhost;
      return 301 https://$host$request_uri;
      include "installdir/nginx/conf/bitnami/bitnami-apps-prefix.conf";
  }

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.

How can I run a command in the Bitnami Nginx Stack?

Load the Bitnami Console and then run the command as usual.

Which components are installed with the Bitnami Nginx Stack?

The Bitnami Nginx Stack ships the components listed below. If you want to know which specific version of each component is bundled in the stack you are downloading, check the README.txt file on the download page or in the stack installation directory. You can also find more information about each component using the links below.

Main components

Dependencies and additional components

  • Varnish proxy cache server
  • ImageMagick tool
  • SQLite database
  • XDebug module
  • Memcache module
  • APC module
  • GD library
  • OpenSSL library
  • CURL library
  • OpenLDAP library
  • PEAR and PECL package manager tools

How can I check the PHP configuration with phpinfo?

Some versions of the Bitnami Nginx Stack include a docs/ folder that contains some PHP examples. Among these is a phpinfo.php script that shows the current PHP configuration and is typically used to check that PHP was installed correctly. In order to be able to access it, follow these steps:

  • Copy the phpinfo.php script from the installation directory to a publicly accessible location under the Web server document root.

     $ cd installdir
     $ cp docs/phpinfo.php nginx/html
    
  • Browse to http://localhost/phpinfo.php.

You should see something similar to this page:

PHP

How to create a custom PHP application?

Many users run a Bitnami stack as a development environment for their own PHP projects (as opposed to running third-party applications such as Joomla! or WordPress). To deploy your PHP application in this environment, you have two options:

  • To make a single PHP application accessible at the root URL of the Web server (for example, http://localhost), simply copy the PHP files into the installdir/nginx/html folder. For an example, take a look at the phpinfo example.
  • To have several applications running, create the same structure used by Bitnami when installing Bitnami PHP applications. Recent versions of Bitnami stacks ship a demo application with this structure to help you get started. To use this, follow the steps below:

    • Copy the installdir/docs/demo folder into the installdir/apps directory.

      $ sudo cp -r installdir/docs/demo installdir/apps
      
    • Add the following line to the end of the installdir/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

      include "installdir/apps/demo/conf/nginx-prefix.conf";
      
    • Restart the Nginx server using the command-line tool.

      $ sudo installdir/ctlscript.sh restart nginx
      

    You should now be able to access the demo application at http://localhost/demo. You should see a "Hello world" message in your browser.

  • If your stack does not include a demo application, or if you prefer to create a custom PHP application from scratch, follow the steps below. These steps assume that your application will live in the installdir/apps/myapp/ directory:

    • Run the following commands to create the directories:

      $ sudo mkdir installdir/apps/myapp
      $ sudo mkdir installdir/apps/myapp/htdocs/
      $ sudo mkdir installdir/apps/myapp/conf
      
    • Create and edit the installdir/apps/myapp/conf/nginx-prefix.conf file and add the line below to it:

      location /myapp {
      alias "installdir/apps/myapp/htdocs/";
      include "installdir/apps/myapp/conf/nginx-app.conf";
      }
      
    • Create and edit the installdir/apps/myapp/conf/nginx-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application's requirements.

      index index.php index.html index.htm;
      location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_read_timeout 300;
      fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
      fastcgi_index index.php;
      fastcgi_param  SCRIPT_FILENAME $request_filename;
      include fastcgi_params;
      }
      
    • Add the following line to the end of the installdir/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

      include "installdir/apps/myapp/conf/nginx-prefix.conf";
      
    • Restart the Nginx server:

      $ sudo installdir/ctlscript.sh restart nginx
      
    • Access the application at http://localhost/myapp.

  • If you want to use a virtual host for an application located at installdir/apps/myapp, edit the installdir/apps/myapp/conf/nginx-vhosts.conf and add the content below to it:

    server {
        listen    80;
        root "installdir/apps/myapp/htdocs/";
        server_name  myapp.example.com www.myapp.example.com;
        include "installdir/apps/myapp/conf/nginx-app.conf";
    }
    server {
        listen    443 ssl;
        root   "installdir/apps/myapp/htdocs/";
        server_name  myapp.example.com www.myapp.example.com;
        ssl_certificate  "installdir/apps/myapp/conf/certs/server.crt";
        ssl_certificate_key  "installdir/apps/myapp/conf/certs/server.key";
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        include "installdir/apps/myapp/conf/nginx-app.conf";
    }
    
    • Add the following line to the end of the installdir/nginx/conf/bitnami/bitnami-apps-vhosts.conf file:

      include "installdir/apps/myapp/conf/nginx-vhosts.conf";
      
    • Restart the Nginx server:

      $ sudo installdir/ctlscript.sh restart nginx
      
    • Access the application at http://myapp.example.com.

How can I deploy my PHP application?

The main directory to deploy your PHP application is installdir/apache2/htdocs. You can copy your PHP application files to that directory and access the application via your browser at http://localhost/.

How to create a full backup of Nginx?

The Bitnami Nginx Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

NOTE: If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

Backup on Linux and Mac OS X

Follow these steps:

  • Change to the directory in which you wish to save your backup.

     $ cd /your/directory
    
  • Stop all servers.

     $ sudo installdir/ctlscript.sh stop
    
  • Create a compressed file with the stack contents.

     $ sudo tar -pczvf application-backup.tar.gz installdir
    
  • Start all servers.

     $ sudo installdir/ctlscript.sh start
    
  • Download or transfer the application-backup.tar.gz file to a safe location.

You should now download or transfer the application-backup.tar.gz file to a safe location.

Backup on Windows

Follow these steps:

  • Stop all servers using the shortcuts in the Start Menu or the graphical manager tool.

  • Create a compressed file with the stack contents. You can use a graphical tool like 7-Zip or WinZip or just right-click the folder, click "Send to", and select the "Compressed (zipped) folder" option.

  • Download or transfer the compressed file to a safe location.

  • Start all servers using the shortcuts in the Start Menu or the graphical manager tool.

Restore on Linux and Mac OS X

Follow these steps:

  • Change to the directory containing your backup:

    $ cd /your/directory
    
  • Stop all servers.

    $ sudo installdir/ctlscript.sh stop
    
  • Move the current stack to a different location:

    $ sudo mv installdir /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directory:

    $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers.

    $ sudo installdir/ctlscript.sh start
    
IMPORTANT: When restoring, remember to maintain the original permissions for the files and folders. For example, if you originally installed the stack as the root user on Linux, make sure that the restored files are owned by root as well.

Restore on Windows

  • Change to the directory containing your backup:

       $ cd /your/directory
    
  • Stop all servers using the shortcuts in the Start Menu or the graphical manager tool.

  • Uninstall the previous services by executing the following command:

        $ serviceinstall.bat
    
  • Create a safe folder named Backups in the desktop and move the current stack to it. Remember to replace PATH with the right location of your folder:

        $ move installdir \PATH\Backups
    
  • Uncompress the backup file using a tool like 7-Zip or Winzip or just double-click the .zip file to uncompress it, and move it to the original directory.
  • Install services by running the following commands from an elevated command prompt:

      $ cd installdir
      $ serviceinstall.bat INSTALL
    
  • Start all servers using the shortcuts in the Start Menu or the graphical manager tool.

How to debug errors in your database?

The main log file is created at installdir/mysql/data/mysqld.log on the MySQL database server host.

nativeInstaller

Bitnami Documentation