Create new config file for your app in the /etc/nginx/sites-enabled folder. Like /etc/nginx/sites-enabled/yourapp.com.conf

Edit your config look like this

server {

 listen 443;

 

 ssl    on;

 ssl_certificate    /path/to/ssl/web/fullchain.pem;

 ssl_certificate_key    /path/to/ssl/web/privkey.pem;

 

 server_name yourapp.com;

 

 location / {

   root /var/www/yourapp.com/web;

   index index.html index.htm;

 

   try_files $uri $uri/ /index.html?$query_string;

 }

 

 location /api {

   proxy_pass http://localhost:8080;

   proxy_http_version 1.1;

   proxy_set_header Upgrade $http_upgrade;

   proxy_set_header Connection ‘upgrade’;

   proxy_set_header Host $host;

   proxy_cache_bypass $http_upgrade;

 }

}

 

server {

 listen 443;

 

 ssl    on;

 ssl_certificate    /path/to/ssl/api/fullchain.pem;

 ssl_certificate_key    /path/to/ssl/api/privkey.pem;

 

 server_name api.yourapp.com;

 client_max_body_size 200m;

 

 location / {

   proxy_pass http://localhost:8080;

   proxy_http_version 1.1;

   proxy_set_header Upgrade $http_upgrade;

   proxy_set_header Connection ‘upgrade’;

   proxy_set_header Host $host;

   proxy_cache_bypass $http_upgrade;

   proxy_redirect        off;

   proxy_set_header      Host $host;

   proxy_set_header      X-Real-IP $remote_addr;

   proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;

   proxy_set_header      Proxy “”;

 }

 proxy_set_header Host $http_host;

 proxy_set_header X-Forwarded-For $remote_addr;

 proxy_set_header X-Forwarded-Proto $scheme;  

}

 

server {

 listen 443;

 

 ssl    on;

 ssl_certificate    /path/to/ssl/seller/fullchain.pem;

 ssl_certificate_key    /path/to/ssl/seller/privkey.pem;

 server_name seller.yourapp.comtop;

 

 location / {

   root /var/www/yourapp.com/seller;

   index index.html index.htm;

 

   try_files $uri $uri/ /index.html?$query_string;

 }

}

 

server {

 listen 443;

 

 ssl    on;

 ssl_certificate    /path/to/ssl/admin/fullchain.pem;

 ssl_certificate_key    /path/to/ssl/admin/privkey.pem;

 server_name admin.yourapp.comtop;

 

 location / {

   root /var/www/yourapp.com/admin;

   index index.html index.htm;

 

   try_files $uri $uri/ /index.html?$query_string;

 }

}

 

server {

 listen 80;

 server_name yourapp.com www.yourapp.com;

 return 301 https://yourapp.com$request_uri;

}

server {

 listen 80;

 server_name api.yourapp.com www.api.yourapp.com;

 return 301 https://api.yourapp.com$request_uri;

}

server {

 listen 80;

 server_name seller.yourapp.comtop www.seller.yourapp.comtop;

 return 301 https://seller.yourapp.comtop$request_uri;

}

server {

 listen 80;

 server_name admin.yourapp.comtop www.admin.yourapp.comtop;

 return 301 https://admin.yourapp.comtop$request_uri;

}

  • Change 8080 to your API port. Change domain, root directory in your app

Restart your nginx $ sudo service nginx restart

Leave a Reply

Your email address will not be published. Required fields are marked *