how to deploy route multiple domain and node server by one nginx server

Posted By : Himanshu sharma | 05-Apr-2016

For ubuntu ,go to /etc/nginx/site-aviable

Create file name as your domain name like app.example.com

Suppose you have to web domain route in single ip and  one domain you have to route your web app and in other admin panel and 3 node server in it

Create two file with domain name in site-aviable

[email protected]:/etc/nginx/sites-available$  ls
api.example.com  app.example.com

and add ip with domain name in /etc/hosts file like

127.0.0.1 localhost
183.62.88.77 api.jeenees.com
183.62.88.77 app.jeenees.com

# 183.62.88.77  is the ip of your domain

and place this content in it

# You may add here your
# server {
#       ...
# }


server {
        listen 80;
        listen [::]:80;

        root /opt/jeenees/jeenees-admin;
          index index.html;

        # Make site accessible from http://localhost/
        server_name api.jeenees.com;

        location / {

                  index index.html;

                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
}
# admin site

 


        location /api/v1/userapi/ {

           proxy_pass http://127.0.0.1:3000/api/v1/userapi/;

            }
# ecommerce data server proxy


  location /api/v1/ecommerceData/ {

           proxy_pass http://127.0.0.1:3001/api/v1/ecommerceData/;
            }

# ecommerce fetching server

  location /api/v1/ecommerceFetch/ {

           proxy_pass http://127.0.0.1:3002/api/v1/ecommerceFetch/;

            }

 

 

        location /facebook {

         proxy_pass http://127.0.0.1:3003/auth/facebook;

        }
       

server {
        listen 8000;
  listen [::]:8000 default_server ipv6only=on;

server_name app.jeenees.com;

root /opt/jeenees/jeenees-admin;
        index index.html index.htm;

        # Make site accessible from http://localhost/
#server_name  localhost;

 location /facebook {

         proxy_pass http://localhost:3003/auth/facebook;

        }


}

 

# then run nginx

sudo service nginx restart

 

THANKS

About Author

Author Image
Himanshu sharma

Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.

Request for Proposal

Name is required

Comment is required

Sending message..