with nginx plugin OPNsense become a strong full featured Web Application Firewall (WAF)
The OPNsense security platform can help you to protect your network and your webservers with the nginx plugin addition.
In old days, install an open source firewall was a very trick task, but today it can be done with few clicks (or key strokes). In this article I'll not describe the detailed OPNsense installation process, but you can watch this video that was extracted from my OPNsense course available in Udemy. The video is in portuguese language, but with the translation CC Youtube feature you may be able to follow it without problems (if you don't are a portuguese speaker ofcourse) :-)
Depend on the platform you are installing the OPNsense, the steps may vary, following the official installation guide:
To install the plugin, follow this simple steps:
- Access your OPNsense firewall web gui: (https://<YOUR_IP>)
2. Go to the Menu: System: Firmware: Plugins
3.Find the os-nginx plugin and click the install option [+]
Before the configuration, we need to understand some terms:
- Upstream Server: The real webserver that will host the web page/application;
- Upstream: The backend where will be configured the server(s);
- Location: The URL pattern that should have an Upstream configured;
- HTTP Server: The frontend that should have one or more Locations configured;
So, our configuration will start with the Upstream Server configuration:
To make the initial configuration, go to the Nginx configuration menu:
1. Upstream Server
The server params will depend on your webserver/application and network environment. To better protection, it's recommended that you set some limits in Maximum Connections/Failures and in the Fail Timeout.
In the above example we are not using TLS in the backend.
The configured Upstream will look like this:
3. Download the NAXSI (WAF) rules
About NAXSI: (extracted from: https://github.com/nbs-system/naxsi)
Technically, it is a third party nginx module, available as a package for many UNIX-like platforms. This module, by default, reads a small subset of simple (and readable) rules containing 99% of known patterns involved in website vulnerabilities. For example,
dropare not supposed to be part of a URI.
Before proceed with the configuration, we will need to download the Naxsi rules, that will be enabled in our Location configuration later.
Go to the Submenu:
Create a new Location:
- Description: Fill with something that makes sense to you;
- URL pattern: To match with your webserver root fill with "/". To match with another path change it to something like "/anotherpath/";
- Enable Security Rules: This option enable the WAF protection. Combined with the Custom Security Policy you will be able to protect your website from the specified policies (group of rules);
- Learning mode: In this mode, the plugin will not block the requests that match with the selected policies, will only log the requests. It's a good idea to adjust your own whitelist rule before start to block requests.
5. HTTP Server
Finally, create your website frontend:
- Server Name: the FQDN name of your website;
- Locations: the Location created in the previous step;
- TLS Certificate / CA Certificate/ Enable Let's Encrypt Plugin: If you want (you should) enable HTTPS (TLS) in your website, these options need to be configured with the your TLS and CA certificate (if you already have a valid one) or you can install and configure the Let's Encrypt Plugin that will create those to you at no cost.
6. OPNsense configuration adjusts
To enable our nginx service without port conflict problems, we'll need to adjust some webgui configurations.
!! Make sure that you have access to your OPNsense from your LAN interface or add the required rules before changing the following configurations !!
Go to the System: Setting: Administration menu
Back to the menu Services: Nginx: Configuration and enable the service:
The final step is to create the required Firewall Rules to allow the HTTP/HTTPS traffic on desired network interface (probabilly the WAN).
I tried to cover in this article the basic configuration of this great plugin to the awesome OPNsense security platform, to provide some website protection. It's possible to get an advanced protection with this plugin, but it will demand many others articles to explore all possibilities.
Thanks to the OPNsense team and community!
If you need some help with OPNsense, open source security or Cloud Managed Security Services: