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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu sharma
Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.