How Hereco Uses Nginx as a Web Server and Reverse Proxy

Every website needs some component accepting the requests, serving the content, and making sure they reach the right place. At Hereco, we accomplish this with Nginx, acting as a web server to serve our content and a reverse proxy to our applications.
Why Hereco Uses Nginx
Nginx is a great tool for this job since its lightweight and efficient. This makes it perfect for handling all the requests going to our site without being too heavy on the server’s resources
Instead of all of our apps having to be exposed to the internet, we can proxy them through Nginx and let it manage their requests instead.
Nginx as a Web Server
The first task Nginx is used for is serving the static content for our website.
Nginx is efficient at serving static content like HTML, CSS, JS, images, fonts, or any others that we might have.
Serving static content is one of the primary functions of a web server, so Nginx is perfect for this. It also handles several aspects of the request-handling process. It can terminate TLS, manage headers, compression, caching, and various other features. This is important since it helps reduce unnecessary overhead on the application by handling as much of the request as possible in Nginx itself. Even the application itself does not have to manage all of the HTTP layer aspects, since that can be handled by Nginx as well.
Nginx as a Reverse Proxy
Nginx is also used as a reverse proxy for our applications.

This allows Nginx to accept requests from the internet and either serve those files itself or pass them on to an application if needed. It means that the applications do not have to be directly exposed to the internet, but can be behind our webserver. This is useful when multiple services are used to power a single website frontend. Nginx can also be used to route requests to different applications or processes depending on what the request is asking for. It allows the website to appear unified to the endusers even if there are several separate processes handling different parts of the website.
Keeping Applications Separate
Separating the application and the webserver is useful since the application itself does not have to manage as much overhead.
The app can be launched on its own, and only have to accept connections from the local interface or from Nginx itself. The application does not need to handle its own TLS or certificate management, and only needs to set up a connection to the Nginx reverse proxy on the machine. This makes launching or restarting the application much more simple as it simply needs to be running somewhere on the system that Nginx can reach it. The same can be said for other aspects of the application as well. The reverse proxy can manage the webserver aspects of the application while the application itself can focus on its primary task.
HTTPS and Connection Management
Nginx can also be used to handle HTTPS connections.
This allows for the application itself to not need to handle TLS encryption or decryption and to have all of the certificates managed in a single place. Nginx can also handle features relating to HTTP/2 and HTTP/3 and their associated encryption and compression features. Having this at the webserver layer allows for application logic to be simpler while still being able to use modern web standards.
Performance and Resource Usage
One of the reasons why Nginx is used in general is because of its performance characteristics.
A webserver application has to be able to handle thousands of connections at once without being too heavy on the system. Using Nginx, the resource usage is low enough that it does not add much overhead on the server itself. In the case of Hereco, it is used to proxy requests to applications and serve static content. It allows the application to be relatively isolated from the webserver aspects of the system, and the low overhead makes sure that it will not have a significant impact on the performance of the system.
Security
Having Nginx as a layer between the applications and the internet allows for better security practices to be used.
The applications only need to be exposed to the local network interfaces behind Nginx and only have to be on the same machine as the webserver. Additionally, Nginx can be used to accept or deny requests based on certain conditions and to add various headers which improve the security of the application itself. This does not give total security, but it adds another step in protecting the application.
A Simple and Flexible Architecture
Finally, one of the main benefits of using Nginx is that it does not require any particular architecture for the applications.
Nginx is flexible enough to be used as a simple webserver for a static page, as a reverse proxy for an application, or a combination of both. It can also handle several other aspects like TLS termination and managing connections. All of this allows hereco to use Nginx to manage things in a simple way that leaves room for expansion as necessary.
Why You Can Use Nginx Too
Nginx is extremely useful for websites because it can be used either as a simple webserver for static assets or as a reverse proxy for applications. It allows for TLS termination, routing, request management, and many other tools to be used. These qualities allow for even small sites to benefit from the performance and flexibility of Nginx.
You do not need a complex infrastructure to take advantage of this. A small website can use Nginx because it fulfills its primary purpose of a webserver, which is to accept the request and decide what to do with it. It can either serve static content directly or route the request to the application that needs to handle it. For Hereco, that lets us have a stable webserver while making sure our applications are kept safe and are easy to manage.