Running Netdata behind Nginx
#
IntroNginx is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server used to host websites and applications of all sizes.
The software is known for its low impact on memory resources, high scalability, and its modular, event-driven architecture which can offer secure, predictable performance.
#
Why NginxBy default, Nginx is fast and lightweight out of the box.
Nginx is used and useful in cases when you want to access different instances of Netdata from a single server.
Password-protect access to Netdata, until distributed authentication is implemented via the Netdata cloud Sign In mechanism.
A proxy was necessary to encrypt the communication to Netdata, until v1.16.0, which provided TLS (HTTPS) support.
#
Nginx configuration fileAll Nginx configurations can be found in the /etc/nginx/
directory. The main configuration file is /etc/nginx/nginx.conf
. Website or app-specific configurations can be found in the /etc/nginx/site-available/
directory.
Configuration options in Nginx are known as directives. Directives are organized into groups known as blocks or contexts. The two terms can be used interchangeably.
Depending on your installation source, you’ll find an example configuration file at /etc/nginx/conf.d/default.conf
or etc/nginx/sites-enabled/default
, in some cases you may have to manually create the sites-available
and sites-enabled
directories.
You can edit the Nginx configuration file with Nano, Vim or any other text editors you are comfortable with.
After making changes to the configuration files:
Test Nginx configuration with
nginx -t
.Restart Nginx to effect the change with
/etc/init.d/nginx restart
orservice nginx restart
.
#
Ways to access Netdata via Nginx#
As a virtual hostWith this method instead of SERVER_IP_ADDRESS:19999
, the Netdata dashboard can be accessed via a human-readable URL such as netdata.example.com
used in the configuration below.
#
As a subfolder to an existing virtual hostThis method is recommended when Netdata is to be served from a subfolder (or directory).
In this case, the virtual host netdata.example.com
already exists and Netdata has to be accessed via netdata.example.com/netdata/
.
#
As a subfolder for multiple Netdata servers, via one NginxThis is the recommended configuration when one Nginx will be used to manage multiple Netdata servers via subfolders.
Of course you can add as many backend servers as you like.
Using the above, you access Netdata on the backend servers, like this:
http://netdata.example.com/netdata/server1/
to reachbackend-server1
http://netdata.example.com/netdata/server2/
to reachbackend-server2
#
Encrypt the communication between Nginx and NetdataIn case Netdata's web server has been configured to use TLS, it is
necessary to specify inside the Nginx configuration that the final destination is using TLS. To do this, please, append
the following parameters in your nginx.conf
Optionally it is also possible to enable TLS/SSL on Nginx, this way the user will encrypt not only the communication between Nginx and Netdata but also between the user and Nginx.
If Nginx is not configured as described here, you will probably receive the error SSL_ERROR_RX_RECORD_TOO_LONG
.
#
Enable authenticationCreate an authentication file to enable basic authentication via Nginx, this secures your Netdata dashboard.
If you don't have an authentication file, you can use the following command:
And then enable the authentication inside your server directive:
#
Limit direct access to NetdataIf your Nginx is on localhost
, you can use this to protect your Netdata:
You can also use a unix domain socket. This will also provide a faster route between Nginx and Netdata:
note: Netdata v1.8+ support unix domain sockets
At the Nginx side, use something like this to use the same unix domain socket:
If your Nginx server is not on localhost, you can set:
note: Netdata v1.9+ support allow connections from
allow connections from
accepts Netdata simple patterns to match against the
connection IP address.
#
Prevent the double access.logNginx logs accesses and Netdata logs them too. You can prevent Netdata from generating its access log, by setting this in /etc/netdata/netdata.conf
:
#
SELinuxIf you get an 502 Bad Gateway error you might check your Nginx error log:
If you see something like the above, chances are high that SELinux prevents nginx from connecting to the backend server. To fix that, just use this policy: setsebool -P httpd_can_network_connect true
.