Report this

What is the reason for this report?

How to Setup a DigitalOcean Load Balancer Domain to a Nginx reverse proxy which proxies a nodejs server

Posted on June 7, 2020

I’ve followed many tutorials that are almost based on my question but none of them worked unfortunately :(. (Note: I’m rookie on making these DevOps stuff :P but I’ll thank you if you could help me).

In order to explain the issue, I will mention what I have done so far:

In my DO(DigitalOcean) LoadBalancer setup

  • Forwards Rules: HTTP on port 80 => HTTP on port 80 and HTTPS on port 443 => HTTP on port 80
  • Algorithm: ‘Least Connections’
  • Health checks: http://0.0.0.0:80/
  • Sticky sessions: ‘Off’
  • SSL: ‘Redirect HTTP to HTTPS’
  • Proxy Protocol: ‘Enabled’
  • Backend Keepalive: Disabled

Also I’ve included a single DO Droplet to this DO LoadBalancer (for testing purpose). However, one doubt I have regarding this is if it’s necessary to turn on the ‘Proxy Protocol’ since I don’t think I need to get the original client’s IP once this LoadBalancer will overlap the Client’s IP with its own IP BUT I left it as is because during testing process, the Nginx server is working with ‘Proxy Protocol’ turned on.

In my DO(DigitalOcean) domain

  • I’ve created a custom domain, i.e. ‘mydomain.com’ which has a ‘A’ type DNS record which points to my DO LoadBalancer IP address.

In my DO(DigitalOcean) Droplet with Ubuntu Server 18.04

  • I’ve a Node.js server which is running locally with port 7890. I’m using the following bash command: screen (creates a background terminal which will be active while is running the Node.js server). The Node.js server is an Express server which has a single GET API using HTTP protocol and it doesn’t have any Authentication or Security process setup there.
  • I’ve installed, run and configured an Nginx server + enabled the instance Firewall to listen 80, 443, and 22 ports.

In the Nginx server, I’ve created my own configuration saved in sites-available folder (absolute path: /etc/nginx/) and made a symlink to sites-enabled to run by the mentioned server and with the following configuration:

server {
        listen  80 proxy_protocol;
        listen 443 ssl proxy_protocol;
        server_name mydomain.com;
        set_real_ip_from {loadBalancerIP};
        location / {
                proxy_pass http://localhost:7890;
                proxy_set_header Host            $proxy_host;
                proxy_set_header X-Real-IP       $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
        }
        location /api {
                proxy_pass http://localhost:7890/api/;
                proxy_set_header Host            $proxy_host;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header X-Real-IP       $remote_addr;
        }
        location ~ /\.ht {
                deny all;
        }
}

Where {loadBalancerIP} is my load balancer’s IP setup in my Digital LoadBalancer.

Also, I have renamed the default configuration set in sites-available folder which nginx server has by default (default file name I renamed to disabled.bkp) and removed the ‘default’ symlink file from sites-enabled in order to avoid Nginx runtime errors.

Issue After setting up those processes, I made an API call to my DO cloud server with the following URL:

https://mydomain.com/api/getData and the server’s response is an HTTP error status code 503 (Service Unavailable). Now, before showing me this error, my Nginx server was working by using the default and my customized configuration AND most important it was showing me the Nginx default web page. After renaming and removing Nginx default configuration files, the 503 error was and still persisting…

The most possible problem I think is the Nginx server setup and my DO LoadBalancer configuration. Also I was thinking to dockerize everything but I don’t know is the ‘proper’ way to go.

Please, I would like to have some guidance or help regarding this issue which is driving me nuts a couple of days.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.