Welcome! Log In Create A New Profile

Advanced

Re: several sibling location block

Ingo Schmidt
June 14, 2017 05:04PM
Hi!

> to nginx, as follows:
>
>
> location / {
>
> # force download for ceratain file types
> location ~* \.(?:fb2|mobi|mp3)$ {
> add_header Content-Disposition "attachment";
> }
> location ~* \.fb2$ {
> add_header Content-type "text/fb2+xml";
> }
> location ~* \.mobi$ {
> add_header Content-type "application/x-mobipocket-ebook";
> }
> location ~* \.mp3$ {
> add_header Content-type "audio/mpeg";
> }
>
> ...
> }
>
> Content-Disposition "attachment" seems to be added properly to the
> header, however not the Content-type. Why? Can several sibling location
> blocks that match be proceeded or only one?
Several things to note here:
- nesting is completely unnecessary here since you use the default
location which always matches (if there are no other rules being more
specific)
- when processing a request, nginx will search for exactly one location
that matches your request, following the rules described in detail in
the docs: http://nginx.org/en/docs/http/ngx_http_core_module.html#location
- regex locations are considered in order or appearance. Your first
location is found and used, and only that one.
- stop thinking apache (I believe I alread told you that? ;-)): check
the mime.types file of nginx in /etc/nginx/. It comes with the
installation and this is how you specify content-type headers. If the
provided mapping doesn't suite you, create your own and include that
instead. So you dont need all your content-type locations at all.

And use the docs, they are pretty concise (sometimes you need to read a
couple of times, but it almost always turns out to be accurate :-))
http://nginx.org/en/docs/

And I promise you once again, once you know how to configure nginx and
once it works for you, you'll wonder how you ever could have used Apache
(just my personal opinion, of course!)

Cheers, Ingo =;->
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

several sibling location block

ST June 13, 2017 12:28PM

Re: several sibling location block

Ingo Schmidt June 14, 2017 05:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 237
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready