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):
    GNU/Linux

  • Was it installed as the root user?
    Yes

  • 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 11.11.11.11.11/wordpress. Now I want this subfolder to point a domain name www.example.com

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

like 111.11.11.11/exaple2 --> www.example2.com
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:

/opt/bitnami/apps/
                 |
                 |-wordpress/
                 |          |
                 |          |- htdocs/
                 |          |- conf/
                 |
                 |-otherApp/
                 |          |
                 |          |- 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";
    server_name  example.com www.example.com;
    
    index index.php index.html index.htm;
    allow 127.0.0.1;
    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 example.com www.example.com; 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,
Jose