Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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
    }
}
share|improve this answer
    
Using this right now. Works like a charm. –  AME Feb 25 '13 at 15:49
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.