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} [Tue Aug 21 14:22:07 2012] GET/one/something => 在 4 毫秒内生成 0 个字节(HTTP/1.1 200) 85 字节中的 2 个标头(核心 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屋!