Codementor Events

How to use NGINX as a reverse proxy to handle web traffic for Nodered

Published Apr 21, 2022
How to use NGINX as a reverse proxy to handle web traffic for Nodered

NGINX is a high-performing and production level web server, extremely simple to confirure and use. There are many ways to use it. One is as a reverse proxy, which means it will handle the traffic coming from the internet a send it back to any other application that requires it. It stays in front of those apps.

For example let's considere we have NodeRed running on a server and listening to the port 1880. NodeRed's webserver is not necessarily good as NGINX for handling web traffic directly as we will use it in front of NodeRed to handle said traffic. The simplest way of doing that is using the proxy_pass directive of the nginx configuration. Let's discover it in this example, assuming a nodered server is already running on 1880 port

upstream nodered {
  server 127.0.0.1:1880
}

server {
  server_name your.domain.name;
    listen 80;
    
    location / {
    	proxy_pass http://nodered;
        include proxy_params;
    }
}

In this example the second line is were you register nodered server to NGINX so it become aware of it and its internal address (address within the machine). That address don't necessarily need to be accessible outside of the server. The 7th line is where you specify a rule to catch all the traffic starting with / and send it to nodered with the proxy_pass directive. include proxy_params is used to include various additionnal and default parameters for proxy_pass provided by NGINX such as

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

You can read more here:
Securing http traffic upstream
You can read more here: Reverse proxy with nginx

I hope you enjoyed reading this, leave a comment if any question or suggestion, you can also hit me a quick message for a mentoring session.

Discover and read more posts from SIMO TCHONANG Adonis Morin
get started
post commentsBe the first to share your opinion
Jose3L
2 years ago

It is necessary to investigate a great number of service providers in order to choose the most suitable proxy service for my requirements. In conclusion, I have made the decision to go with the trustworthy and high-quality service that is offered by https://infatica.io . In the past, working online was fraught with peril and a significant time commitment. It is much simpler and less dangerous now.

Show more replies