简体   繁体   English

如何在Apache代理下部署Django Gunicorn?

[英]How can I deploy Django Gunicorn under Apache proxy?

I've run through the documentation and am hitting the same pages over and over again. 我遍历了文档,并一遍又一遍地浏览相同的页面。 At present I've found documentation to run off an existing myapp.wsgi file, but documentation for how to make an appropriate wsgi file is a little harder to find. 目前,我已经找到了运行现有myapp.wsgi文件的文档,但是很难找到有关如何制作适当的wsgi文件的文档。

If I want to make, proxied by Apache, the equivalent of, on an older version of Gunicorn etc.: 如果要在Apache代理下制作与之等效的Gunicorn等旧版本,请执行以下操作:

python manage.py run_gunicorn 0.0.0.0:8888

what should I be doing to supply a WSGI file for: 为提供WSGI文件应该怎么做:

gunicorn project.wsgi:application

Thanks, 谢谢,

Why do you think you need a special wsgi file? 为什么您认为需要特殊的wsgi文件? You just use exactly the same one you would use for any other deployment. 您只需要使用与其他部署完全相同的方式即可。

I assume you're not asking about the content of the wsgi file (which is often pretty standard) but how to assemble a gunicorn command line that allows gunicorn to find/use the wsgi file for your project? 我假设您不是在询问wsgi文件的内容(通常是很标准的),而是如何组装允许gunicorn为您的项目查找/使用wsgi文件的gunicorn命令行?

When deploying to a staging server, I recall having a problem getting the Python path set so that gunicorn could find the proper wsgi file for my app. 部署到登台服务器时,我记得设置Python路径时遇到问题,以便gunicorn可以为我的应用找到正确的wsgi文件。 Here is a trimmed version of the gunicorn command that I ended up using: 这是我最终使用的gunicorn命令的修剪版本:

gunicorn --pythonpath /some_path/my_app/my_app my_app.wsgi:application

In plain English, starting from the right and working backward: 用简单的英语,从右开始并向后工作:

  • There is a function named application inside a the wsgi.py file wsgi.py文件中有一个名为application的函数
  • The wsgi.py file is inside a module named my_app (which in this case is a directory containing a __init__.py file) wsgi.py文件位于名为my_app的模块内(在本例中为包含__init__.py文件的目录)
  • The my_app module is located at /some_path/my_app/my_app , so this needs to be on the PYTHONPATH. my_app模块位于/some_path/my_app/my_app ,因此它必须在PYTHONPATH上。

So the full path to your wsgi.py is: 因此,您的wsgi.py的完整路径是:

/some_path/my_app/my_app/my_app/wsgi.py . /some_path/my_app/my_app/my_app/wsgi.py

In the same directory as wsgi.py is a __init__.py file, which causes Python to recognize that directory as a module. wsgi.py相同的目录中有一个__init__.py文件,该文件使Python将该目录识别为模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM