如何从 Web 访问我的 Gunicorn 服务的 Flask 应用程序?
How can I access my Gunicorn served Flask app from the web?
关于以下文档:
Gunicorn¶ Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX.
It’s a pre-fork worker model ported from Ruby’s Unicorn project. It
supports both eventlet and greenlet. Running a Flask application on
this server is quite simple: gunicorn myproject:app Gunicorn provides
many command-line options – see gunicorn -h. For example, to run a
Flask application with 4 worker processes (-w 4) binding to localhost
port 4000 (-b 127.0.0.1:4000):
gunicorn -w 4 -b 127.0.0.1:4000 myproject:app
一切都很好,但是,文档没有说明如何配置端口 4000 以便可以从 Web 访问。
我希望能够像下面这样握手,
www.mysite.com:4000
并得到回复。
我的应用程序在 Flask 的开发服务器和本地的 Gunicorn 上运行良好。我只是不知道如何配置它以在我的云实例上工作,以便我可以发帖和获取。
您不应该在网络上提供 gunicorn。相反,您应该将它与反向代理一起使用,例如 nginx。
gunicorn 文档 full example 配置 nginx 以反向代理到您的 gunicorn 进程。
关于以下文档:
Gunicorn¶ Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX. It’s a pre-fork worker model ported from Ruby’s Unicorn project. It supports both eventlet and greenlet. Running a Flask application on this server is quite simple: gunicorn myproject:app Gunicorn provides many command-line options – see gunicorn -h. For example, to run a Flask application with 4 worker processes (-w 4) binding to localhost port 4000 (-b 127.0.0.1:4000):
gunicorn -w 4 -b 127.0.0.1:4000 myproject:app
一切都很好,但是,文档没有说明如何配置端口 4000 以便可以从 Web 访问。
我希望能够像下面这样握手,
www.mysite.com:4000
并得到回复。 我的应用程序在 Flask 的开发服务器和本地的 Gunicorn 上运行良好。我只是不知道如何配置它以在我的云实例上工作,以便我可以发帖和获取。
您不应该在网络上提供 gunicorn。相反,您应该将它与反向代理一起使用,例如 nginx。
gunicorn 文档 full example 配置 nginx 以反向代理到您的 gunicorn 进程。