Skip to main content
 首页 » 编程设计

python之可以用uwsgi协议(protocol)调用http吗

2025年05月04日11xxx_UU

这是一个数据流: http <--> nginx <--> uWSGI <--> python webapp

我猜 nginx 中有 http2uwsgi 传输,uWSGI 中有 uwsgi2http。

如果我想直接调用 uWSGI 来测试 webapp 中的 API 怎么办?

实际上我正在使用金字塔。只需在 .ini 中配置 [uwsgi] 并运行 uWSGI。但我想测试 uWSGI 是否正常保持 webapp 功能,uWSGI 套接字不能通过 http 直接访问。

请您参考如下方法:

尝试使用 uwsgi_curl

$ pip install uwsgi-tools 
 
$ uwsgi_curl 10.0.0.1:3030 /path 

或者如果你需要做一些更多的请求尝试来自同一个包的uwsgi_proxy

$ uwsgi_proxy 10.0.0.1:3030 
Proxying remote uWSGI server 10.0.0.1:3030 "" to local HTTP server 127.0.0.1:3030... 

所以你可以在本地浏览 http://127.0.0.1:3030/ .

如果您的应用程序只允许某些Host header ,您也可以指定主机名

$ uwsgi_curl 10.0.0.1:3030 host.name/path 
 
$ uwsgi_proxy 10.0.0.1:3030 -n host.name 

如果应用程序有静态文件,您可以使用 -s 参数将此类请求重定向到您的前端服务器。如果需要,您还可以指定不同的本地端口。