使用uwsgi运行Falcon应用

5 投票
2 回答
6566 浏览
提问于 2025-04-18 08:54

我刚开始学习Falcon(http://falcon.readthedocs.org/en/latest/user/quickstart.html),但是它需要一个运行中的网络服务器,文档建议使用uwsgi或gunicorn。

虽然他们提到了如何用gunicorn来使用它。

$ pip install gunicorn  #install
$ gunicorn things:app   #and run app through gunicorn.

但我想用uwsgi来运行这个示例应用,但我不知道该怎么做。

我已经安装了它,使用了命令pip install uwsgi,还安装了gevent,这是在这里建议的:http://falcon.readthedocs.org/en/latest/user/install.html

但是接下来该怎么办呢?有人能指导我一下吗?

2 个回答

2

你可以使用uwsgi.ini文件来存储配置,这样运行起来会更简单。这是设置uwsgi作为服务的好方法。这里面还涉及到虚拟环境的配置。

[uwsgi]
http = :8000
chdir = /home/user/www/uwsgi-ini
virtualenv = /home/user/www/uwsgi-ini/venv/
wsgi-file = main.py
callable = app
processes = 4
threads = 2
stats = 127.0.0.1:9191

然后在应用程序的文件夹里运行:

uwsgi uwsgi.ini

使用虚拟环境的命令

uwsgi --http :8000 --wsgi-file main.py --callable app -H $(pwd)/venv/
9

你可以在uWSGI的文档网站上找到答案,特别是可以试试这个页面:

http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html

我自己没有用过Falcon或者uWSGI,但看起来你可能可以这样做:

uwsgi --wsgi-file things.py --callable app

撰写回答