我有一个目录结构我想要服务,包含文件作为二进制和一些关于他们作为JSON的元信息。 对于一些目录,我需要在运行中计算一些事情并提供服务。 我想要使用龙卷风来计算和提供这些信息。
这里是一个例子:
> 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
如果你的用例是“提供静态文件,如果它们存在,否则发送一切龙卷风”,你可以用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 eg proxy_set_header } }
你可以用nginx来检查?diesel是否正在通过在location = / block中寻找$arg_diesel来调用。
location = / { if ( $arg_diesel ) { proxy_pass http://tornado; } }
location = / 不是 location / 。 location = /只会被请求不是在一个文件夹这样/?diesel ,而不是/somepath/?diesel而location /将匹配的一切。
文档: http : //nginx.org/r/location