![](/img/trans.png)
[英]how can I use callfromthread to call a method of a protocol in twisted?
[英]Can I use the uwsgi protocol to call http?
这是一个数据流:http <--> nginx <--> uWSGI <--> python webapp
我猜nginx中有http2uwsgi传输,uWSGI中有uwsgi2http。
如果我想直接调用 uWSGI 在 webapp 中测试 API 怎么办?
实际上我正在使用金字塔。 只需在.ini 中配置 [uwsgi] 并运行 uWSGI。 但我想测试uWSGI是否正常持有webapp function,http不能直接访问uWSGI套接字。
尝试使用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
头,则还可以指定主机名
$ uwsgi_curl 10.0.0.1:3030 host.name/path
$ uwsgi_proxy 10.0.0.1:3030 -n host.name
如果应用程序具有静态文件,则可以使用-s
参数将此类请求重定向到前端服务器。 如果需要,您还可以指定其他本地端口。
首先,考虑以下问题:
如果确定可以访问,则可以直接调用http://hostname:port/path/to/uWSGI
进行API直接访问。
从我假设的问题出发,您想直接使用uWSGI运行与WSGI兼容的应用程序并打开HTTP-Socket。 您可以通过配置uwsgi.ini(或任何文件名)来实现
http=127.0.0.1:8080
uwsgi现在将打开一个HTTP套接字,该套接字在端口8080上侦听来自localhost的传入连接(请参阅文档: http : //uwsgi-docs.readthedocs.org/en/latest/HTTP.html )
或者,您可以使用http参数直接从命令行启动过程:
$ uwsgi --http=127.0.0.1:8080 --module=yourapp:wsgi_entry_point
如果您使用unix-sockets配置uwsgi,nginx可以通过uwsgi-protocol( http://uwsgi-docs.readthedocs.org/en/latest/Protocol.html )与该套接字通信。
请记住,如果您通常通过nginx提供静态内容(css,javascript,图像),则如果直接运行uwsgi,也需要进行设置。 但是,如果您只想测试REST-API,这应该可以为您解决。
我知道这是一个老问题,但我只需要这个,发现这个 docker+nginx 解决方案最适合我
cat > /tmp/nginx.conf << EOF
events {}
http {
server {
listen 8000;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
}
}
EOF
docker run -it --network=host --rm --name uswgi-proxy -v /tmp/nginx.conf:/etc/nginx/nginx.conf:ro nginx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.