Can I use the uwsgi protocol to call http?

不羁岁月 提交于 2019-12-02 03:59:21

Try using uwsgi_curl

$ pip install uwsgi-tools

$ uwsgi_curl 10.0.0.1:3030 /path

or if you need to do some more requests try uwsgi_proxy from the same package

$ 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...

so you can browse it locally at http://127.0.0.1:3030/.

If your application allows only certain Host header, you can specify host name as well

$ uwsgi_curl 10.0.0.1:3030 host.name/path

$ uwsgi_proxy 10.0.0.1:3030 -n host.name

If application has static files, you can redirect such requests to your front server using -s argument. You can also specify different local port if needed.

First, consider those questions:

  • On which port is uWSGI running?
  • Is uWSGI running on your or on a remote machine?
  • If it's running on a remote machine, is the port accessible from your computer? (iptables rules might forbid external access)

If you made sure you have access, you can just call http://hostname:port/path/to/uWSGI for direct API access.

From your question I'm assuming, you want to directly run your WSGI-compliant app with uWSGI and open an HTTP-Socket. You can do so by configuring your uwsgi.ini (or whatever the filename is) with

http=127.0.0.1:8080

uwsgi will now open an HTTP-socket that listen on port 8080 for incoming connections from localhost (see documentation: http://uwsgi-docs.readthedocs.org/en/latest/HTTP.html)

Alternatively you can directly start your process from the command-line with the http-parameter:

$ uwsgi --http=127.0.0.1:8080 --module=yourapp:wsgi_entry_point

If you use unix-sockets to configure uwsgi nginx is able to communicate with that socket via the uwsgi-protocol (http://uwsgi-docs.readthedocs.org/en/latest/Protocol.html).

Keep in mind, that if you usually serve static content (css, javascript, images) through nginx you will need to set that up, too, if you run uwsgi directly. But if you only want to test a REST-API this should work out for you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!