Nginx-在uwsgi_pass之前重写request_uri [英] Nginx - Rewrite the request_uri before uwsgi_pass
问题描述
我有一个Nginx虚拟主机,其配置如下:
I have a Nginx vhost than is configured as such:
...
location /one {
include uwsgi_params;
uwsgi_pass unix:///.../one.sock;
}
location /two {
include uwsgi_params;
uwsgi_pass unix:///.../two.sock
}
...
这是课程的简化配置
当我请求/one/something
时,我希望我的Python脚本将/something
接收为request_uri
.
When I request /one/something
I would like my Python script to receive /something
as request_uri
.
我正在使用BottlePy,但希望由Nginx处理,而不是在我的Python代码中处理.
I'm using BottlePy but would like this to be handled by Nginx and not in my Python code.
我可以做类似uwsgi_param REQUEST_URI replace($request_uri, '^/one', '')
的事情吗?
Can I do something like uwsgi_param REQUEST_URI replace($request_uri, '^/one', '')
?
修改
这是我的Python代码发出的请求: [pid:30052 | app:0 | req:1/1](){42 vars in 844 bytes} [2012年8月21日星期二14:22:07] GET/one/something =>在4毫秒内生成了0字节(HTTP /1.1 200)2个报头,共85个字节(核心0上的0个开关)
Here is the request from my Python code: [pid: 30052|app: 0|req: 1/1] () {42 vars in 844 bytes} [Tue Aug 21 14:22:07 2012] GET /one/something => generated 0 bytes in 4 msecs (HTTP/1.1 200) 2 headers in 85 bytes (0 switches on core 0)
所以Python可以,但uWSGI不能.
So Python is OK but uWSGI is not.
该如何解决?
推荐答案
location /one {
rewrite /one/(.+) /$1 break;
include uwsgi_params;
uwsgi_pass unix:///.../one.sock;
}
这篇关于Nginx-在uwsgi_pass之前重写request_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!