0

I have a directory structure I want to serve, that contains files as binary and some meta-information about them as json. for some directories, I need to compute some things on the fly and serve that. I want to compute and serve that information using tornado.

Here is an example:

> ls /manufacturers/*
  audi/
  audi.json
  mercedes/
  mercedes.json

> wget http://localhost/manufactures/audi.json
  returns the json file using nginx static serving
> wget http://localhost/?diesel
  returns a json file with manufactures that 
  create cars with diesel engines computed by and using tornado
AME
  • 135
  • 6

2 Answers2

3

You can check with nginx whether ?diesel is being called by looking for $arg_diesel in the location = / block.

location = / {

    if ( $arg_diesel ) {
        proxy_pass http://tornado;
    }

}

location = / is not the same as the location /. location = / will only be called for requests that aren't in a folder such /?diesel, but not /somepath/?diesel whereas the location / will match everything.

Documentation: http://nginx.org/r/location

VBart
  • 8,159
  • 3
  • 24
  • 25
sjdaws
  • 206
  • 1
  • 5
2

If your use-case is "serve static files if they exist, otherwise send everything to tornado", you can do that with try_files:

upstream upstream_tornado {
    server http://127.0.0.1:8080;
    # ...or wherever
}
server {
    listen 80;
    server_name localhost;
    root /path/to/wherever;

    try_files  $uri @tornado;

    location @tornado {
        proxy_pass http://upstream_tornado;
        # Other proxy stuff e.g. proxy_set_header
    }
}
nickgrim
  • 4,336
  • 1
  • 17
  • 27