Mastering Nginx

(Ron) #1
Chapter 7

[ 179 ]

Then we set up NGINX to use this module to do the mapping:


http {

# this path is relative to the main configuration file
perl_modules perl/lib;

perl_require upstreammapper.pm;

# we'll store the result of the handler in the $upstream variable
perl_set $upstream upstreammapper::handler;

Then we pass the request along to the correct upstream server:


location / {

include proxy.conf;

proxy_pass http://$upstream;

}

}

We have seen a very simple example of implementing some configuration logic in a


Perl handler. Just about any kind of special requirement can be done in a similar way.


Request processing in a Perl handler should be as well-defined
as possible. Whenever NGINX has to wait on a Perl handler
finishing, the whole worker responsible for handling that
request will block. So, any I/O or DNS-related tasks should
be done outside of a Perl handler.

Creating a secure link


You may have cause to protect certain content on your site, but do not want to


integrate full user authentication to allow access to that content. One way of enabling
this is to use NGINX's securelink module. By passing configure the --with-http


secure_link switch at compile time, you get access to the secure_link_secret


directive, and its corresponding variable $secure_link.

Free download pdf