// 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.

1,

ancient_browser “msie 6.0″;

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

http://gist.github.com/228769

(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.

2.

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.

3.

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)

4.

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.

5.

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.

6.

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.

Discussion

No comments for “NGINX Configuration Files and ReWrites”

Post a comment

You must be logged in to post a comment.

Categories

canadian online pharmacy :-) viagra professional price canadian online pharmacy FDA CIPA approved cialis super active online online pharmacy +/- viagra professional Health, beauty products buy generic viagra can now be ordered online. canadian online pharmacy