.. _example-webserver-nginx:

=====================
 nginx configuration
=====================

This example describes how to set up nginx for serving content
generated by  munin.

This document describes two alternative configurations:

1. serving static graphs and HTML generated by munin-cron
2. proxy traffic to munin-httpd


Serving cron-made graphs and HTML
=================================

Nginx is quite good at serving static files, and as such the configuration is
mostly in place already.

The paths are as in use on a Debian Linux system.
Add the following to /etc/nginx/sites-enabled/default::

    location /munin/static/ {
            alias /etc/munin/static/;
            expires modified +1w;
    }

    location /munin/ {
            auth_basic            "Restricted";
            # Create the htpasswd file with the htpasswd tool.
            auth_basic_user_file  /etc/nginx/htpasswd;

            alias /var/cache/munin/www/;
            expires modified +310s;
    }


If this is a dedicated Munin server, you might want to redirect the front
page as well::

    location / {
            rewrite ^/$ munin/ redirect; break;
    }


Using munin-httpd
=================

You can use `nginx as a proxy`_ in front of munin-httpd.

This enables you to add `transport layer security`_ and
`http authentication`_ (not included in this example).

.. index::
   triple: example; munin-httpd; nginx configuration

::

    location /munin/static/ {
        alias /etc/munin/static/;
    }

    location /munin/ {
        proxy_pass http://localhost:4948/;
    }

.. _`nginx as a proxy`:
   http://nginx.org/en/docs/http/ngx_http_proxy_module.html

.. _`transport layer security`:
   http://nginx.org/en/docs/http/configuring_https_servers.html

.. _`http authentication`:
   http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
