3

I have installed munin (for the time being available here: http://brailsford.xyz/munin ) the problem is that whilst the core loads from /var/cache/munin/www - none o the static files load.

I have the following in my nginx config:

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

    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;
    }

AutoIndex is there for a proof: the folder is accessible: https://brailsford.xyz/munin/static/

However, clicking on a file in that folder gives a 404, and the nginx error log shows this:

[error] 22570#0: *50 open() "/data/www/brailsford.xyz/munin/static/style-new.css" failed (2: No such file or directory)

/data/www/brailsford.xyz is my root specified in the overall server clause.

Any suggestions would be greatly appreciated :)

EDIT 1:

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff)$ {
            expires 1w;
    }
AviateX14
  • 175
  • 1
  • 6
  • What happens if you use `location /munin/static/(.*)$` and `alias /etc/munin/static/$1;`? – Kyle Mar 11 '16 at 21:44
  • Do you have a regex location matching `.css` files? – Richard Smith Mar 11 '16 at 21:56
  • Still picks up the wrong path directory index of "/var/cache/munin/www/static/" is forbidden @kyl191 – AviateX14 Mar 11 '16 at 21:56
  • @RichardSmith Only for expiry - see the location block I just added in my edit. – AviateX14 Mar 11 '16 at 21:58
  • 1
    That will do it. Location blocks are not additive in `nginx`. Try `location ^~ /munin/static/ { ... }` which will make it override any regex location (hopefully there are no PHP files in there). – Richard Smith Mar 11 '16 at 22:00
  • @RichardSmith that did it, do you want to post your comment as an answer? I have another problem now with the graphs not loading - think it's looking in the wrong place, I'll look at that one later :( – AviateX14 Mar 11 '16 at 22:04

1 Answers1

2

The location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff)$ block takes precedence for any URIs which end with .css, which means that nginx tries to use the wrong value for root.

Use the ^~ modifier on the prefix location to make it take precedence over any regex location.

For example:

location ^~ /munin/static/ { 
    ...
}

This assumes that the location does not have any special content, such as .php files.

See this document for details.

Richard Smith
  • 12,834
  • 2
  • 21
  • 29
  • This saved my bacon, kept looking all over why the location alias was being overwritten and this was what fixed it. When trying to implement xsendfile for Moodle. – Caperneoignis Jun 03 '19 at 17:04