Hivepod Blog

How to Set up an Hivepod Application as Nginx Server Blocks on Ubuntu 14.04 LTS?

Posted by Jaime Serra on Nov 30, 2015 15:55:34 AM

In this post we will explain how to deploy an application using Nginx Server Blocks.

We assume that you have generated the code of your application and that you have deployed Nginx on a separate server.

An Hivepod application contains 4 areas that need to be deployed independently of each other:

  • The Admin Console (/#/login)
  • The Microservice API (/api)
  • The (optional) OAuth Callback
  • The Ping API

In this post we aim at deploying the following namespace:

Area URL
admin console http://admin.mydomain.com/#/login
oauth callback http://admin.mydomain.com/oauth2/{provider}/callback
api http://www.mydomain.com/api
ping http://www.mydomain.com/ping

The Nginx Server Block definitions can be found at /etc/nginx/sites-available/.

You will need two configurations files:

  • mydomain.com
  • admin.mydomain.com
mydomain.com file
server {
   listen 80;
   listen [::]:80;

   root /var/www/mydomain.com/public_html;
   index index.html index.htm;

   server_name mydomain.com www.mydomain.com;

   location / {

        proxy_pass http://1.2.3.4;
        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 X-Forwarded-Proto $scheme;
     }

   location /ping {
        proxy_pass http://5.6.7.8:5000;
        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 X-Forwarded-Proto $scheme;
    }
  
    location /api {
        proxy_pass http://5.6.7.8:5000;
        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 X-Forwarded-Proto $scheme;
    }
}

NOTE: I assume that your website is hosted at 1.2.3.4 and your hivepod app at 5.6.7.8:5000.

admin.mydomain.com file
server {
    listen 80;
    listen [::]:80;

    root /var/www/gliiph.com/public_html;
    index index.html index.htm;

    server_name admin.gliiph.com www.admin.gliiph.com;

    location / {

        proxy_pass http://5.6.7.8:5000;
        proxy_set_header  X-Forwarded-Host $host;
    }

    location /oauth2 {
        proxy_pass http://5.6.7.8:5000;
        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 X-Forwarded-Proto $scheme;
    }
}

Now you need to link these two configuration files to the /etc/nginx/sites-enabled directory:

$ ln -s /etc/nginx/sites-available/admin.mydomain.com /etc/nginx/sites-enabled/admin.mydomain.com

$ ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/mydomain.com

The last step is to restart Nginx:

$ service nginx restart

If you need more information on how to setup server block on Nginx, this excellent article provides all the background information you’ll need.

If you need to deploy Nginx in a Highly Available mode, this article provides all the detailed steps using Keepalived.

If you want to setup OAuth2, here is how you would configure the Google credentials panel:


Written by Jaime Serra