// you’re reading...

The Industry

NGINX Configuration Files and ReWrites

Some of this post will just be random notes, some will be more descriptive of just what madness occurs inside one of these files. For version 0.7.63.


ancient_browser “msie 6.0″;

Whether quotes, like on the nginx site, capitalized or not, or unquoted as it is here:


(linked to from the main site), the instruction: if ($ancient_browser) is true for the google bot. If you want your site crawled this ain’t so good. In fact, horrible.


As mentioned before try_files appears to do nothing at all. Instead one can use if -f filename. This generates an error for each try in the error.log.


When performing a break at the end of a rewrite or in an if (…) { break; } what this does is send the process back to the top of the configuration file again, this time with the new modified $filename_uri ($request_uri is not changed by rewrites, tho you can assign it a new value, if I remember correctly)


Our backend is an apache on a different ip. We needed to use:

resolver: xx.xx.xx.xx

and the x ip worked whether we used the ip of the backend, or ips found in /etc/resolv.conf. Nginx did seem to need this instruction regardless.


For speed (and in our case to make things work) we added several lines like:

location = /robots.txt {
location = /favicon.ico {
and for the top level sitemap.

which are called quite frequently and the ‘=’ comparison is reported by nginx to be the fastest and first comparisons made when a url is received.


The real problem with Nginx programming is the inability to AND more than 2 things together - doing this only by specifying a Location - for the first part of the AND, and inside a Location using an ‘if’ statement for the second.

As a stupid example:

location ^~ /images {
if (request_uri ~ .gif) {


The only way to AND 3 or more things together is to create ‘faux’ locations, and redirect 302 to the ‘faux’ location in which the 3rd AND, using an if statement, can occur. More contrived examples…

location ^~ /images {
if (request_uri ~ .gif) {
rewrite ^(.*)$ /faux/$request_uri;

location ^~ /faux {
if ($subdomain = supersized) {

In Apache, one just has to add as many RewiteCond as one cares to. Very easy. Nginx’s overly constrained environment is kind of fun, in a masochistic, how can I actually do this, who cares how many lines of code and contortions it takes… can it even be DONE? kind of way.


No comments for “NGINX Configuration Files and ReWrites”

Post a comment

You must be logged in to post a comment.


canadian online pharmacy FDA CIPA approved cialis super active online U.S. manufactured online pharmacies ~{:# cialis soft use patients to once again. FDA approved Canadian drug pharmacy *?( Canadian pharmacy delivering medicines at your door.