使用 uWSGI 代理某些请求

Using uWSGI to proxy certain requests

我正在尝试将所有请求 /other 发送到另一台服务器,例如 google。据我了解配置,我应该能够在配置文件中做这样的事情:

[uwsgi]
master = 1
buffer-size = 65535
die-on-term = true
# HTTP
http-socket = 0.0.0.0:80
# App
module = manage:app
# Async processes
gevent = 100
processes = 4
route-if = equal:${PATH_INFO};/other http:216.58.204.78,www.google.com

这不起作用,因为日志刚刚

error routing request to http server 216.58.204.78
[pid: 9|app: -1|req: -1/11] 172.18.0.1 () {36 vars in 759 bytes} [Thu Sep 20 14:51:55 2018] GET /other => generated 0 bytes in 0 msecs via route() (HTTP/1.1 500) 0 headers in 0 bytes (1 switches on core 99)

根据uwsgi doc,您需要以HOST:PORT的形式指定外部HTTP服务器地址,例如config:

route-if = equal:${PATH_INFO};/s http:220.181.111.188:80,www.baidu.com

结果:

[pid: 5113|app: -1|req: -1/1] 127.0.0.1 () {24 vars in 249 bytes} [Tue Sep 25 17:58:33 2018] GET /s => generated 118322 bytes in 34 msecs via route() (HTTP/1.1 200) 18 headers in 944 bytes (0 switches on core 0)