Add two or more domains in single instance of nginx

[IMPORTANT, please fill the questions]

  • Application name and version:
    Nginx 1.10.1-1

  • Is it an installer, cloud image or virtual machine?:
    Virtual machine

  • Operative system/Platform (Linux, Windows, OSX)(x86/x64):

  • Was it installed as the root user?

  • Is there anything you’ve done and/or tried with the application before posting here?
    E.g. changed permissions or installed a plugin: New

We assume you are using Bitnami to deploy your application.
Describe here your question/suggestion/issue and how to reproduce it.
I have installed nginx and installed wordpress using bitnami app in a subfolder. like Now I want this subfolder to point a domain name

I want to add couple of more sub folders in future also

like -->
I have already changed dns part … but its not pointing to subfolder. I know it wont. Some one please sugest me how to do this.
I am using google cloud

Hello @malliktajmahal,

You need to use different server blocks (a server block is like a VirtualHost in Apache in case you are more familiarized with the Apache naming) with each application you have on your server.

For instance, imagine you have the following folder structure:

                 |          |
                 |          |- htdocs/
                 |          |- conf/
                 |          |
                 |          |- htdocs/
                 |          |- conf/
                 |          |

In each htdocs folder you will have the application code and in the conf folder you will have the nginx configuration of each application.

In both conf folders you can create a file nginx-vhosts.conf with this content:

server {

    listen    80;
    root   "/opt/bitnami/apps/<APPLICATION>/htdocs";
    index index.php index.html index.htm;
    deny all;

    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;

Please, change the <APPLICATION> and server_name; with their correct values.

Next step is to include those configurations in the main nginx.conf configuration file. In the Bitnami Nginx Stack you have only to edit the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf file and add to it the following lines:

include "/opt/bitnami/apps/<APPLICATION1>/conf/nginx-vhosts.conf";
include "/opt/bitnami/apps/<APPLICATION2>/conf/nginx-vhosts.conf";

Finally, please note that each application could need additional changes in their configuration. For example, WordPress needs to have the WP_SITEURL and WP_HOME variables set as follow in the /opt/bitnami/apps/wordpress/htdocs/wp-config.php file:

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');                   
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/'); 

Hope it helps,