Mastering Nginx

(Ron) #1
Chapter 7

[ 181 ]

To ensure that links without a hash will not work, we can add an additional link to


our HTML:


<a href="/downloads/bare_link.pdf">bare link</a>

Calling this link reports a "403 Forbidden" error, as it should.


The technique for generating a secure_link module described
before is just one possible way of solving this type of problem.
NGINX itself even offers an alternative way described at
http://wiki.nginx.org/HttpSecureLinkModule.

Generating images


Instead of writing an image manipulation module for your application, you can
configure NGINX to handle some simple transformations. If your image-manipulation


needs are as simple as rotating an image, resizing it, or cropping it, NGINX is capable


of doing this for you.


To make use of this functionality, you need to have installed the libgd library, and
enabled the image_filter module at compile-time (--with-http_imagefilter


module). If that is the case, you now have use of the directives in the following table:


The GD library (libgd) is an image generation library written in C.
It is often used in combination with a programming language such as
PHP or Perl to generate images for websites. NGINX's image_filter
module uses libgd to provide the capability of creating a simple
image resizing proxy, which we discuss in the following example.

Table: Image filter directives

Directive Explanation
empty_gif Causes a 1x1 pixel transparent GIF to be
emitted for that location.
image_filter Transforms an image according to one of the
following parameters:


  • off: Turns off image transformation.

  • test: Ensures that responses are
    either GIF, JPEG, or PNG images.
    If not, an error 415 (Unsupported
    Media Type) is returned.

Free download pdf