mn-jwg
Last Updated: February 25, 2016
·
337
· geetotes

How to break the internet (literally)

Sometimes you need to serve up files on nginx with a question mark in the name. On nginx, this is easy:

location / {
        root /var/www;
        try_files $uri$is_args$args $uri;
}

How does this break the internet?

Well, question marks are normally interpreted by servers as a flag for query strings for a GET request.

Let's break down the request /feaux?bar=bazz

/feaux is our URI

bar=bazz is our query string

By telling try_files to first concatenate and look up $uri, the $is_args (the question mark), and the $args (the query string) and serve up that file, you're preventing your website from figuring out what to do with the query strings. If every website did this, the internet would break.

Why would you ever need this snippet? IDK, sometimes you gotta serve up a bunch of static files with question marks in their filenames.