{"title":"如何使用 Gunicorn 托管 Django","version":"2.2","locale":"zh-hans","docname":"howto/deployment/wsgi/gunicorn","url":"/zh-hans/2.2/howto/deployment/wsgi/gunicorn/","canonical":"https://djangodocs.dev/zh-hans/2.2/howto/deployment/wsgi/gunicorn/","summary":"Gunicorn ('Green Unicorn') 是一个 UNIX 下的纯 Python WSGI 服务器。它没有其它依赖，容易安装和使用。 安装 Gunicorn Link to this heading # 安装 gunicorn 非常简单，只要执行 pip install gunicorn 即可。更多细节请参考…","html":"<h1>如何使用 Gunicorn 托管 Django<a class=\"heading-anchor\" href=\"#how-to-use-django-with-gunicorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://gunicorn.org/\">Gunicorn</a> ('Green Unicorn') 是一个 UNIX 下的纯 Python WSGI 服务器。它没有其它依赖，容易安装和使用。</p>\n<section id=\"installing-gunicorn\">\n<h2>安装 Gunicorn<a class=\"heading-anchor\" href=\"#installing-gunicorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>安装 gunicorn 非常简单，只要执行 <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span> <span class=\"pre\">install</span> <span class=\"pre\">gunicorn</span></code> 即可。更多细节请参考 <a class=\"reference external\" href=\"https://docs.gunicorn.org/en/latest/install.html\">gunicorn documentation</a>。</p>\n</section>\n<section id=\"running-django-in-gunicorn-as-a-generic-wsgi-application\">\n<h2>把 Django 当作普通 WSGI 应用在 Gunicorn 中运行<a class=\"heading-anchor\" href=\"#running-django-in-gunicorn-as-a-generic-wsgi-application\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>安装 Gunicorn 之后，可以使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">gunicorn</span></code>  命令启动 Gunicorn 服务进程。最简模式下，只需要把包含了 WSGI 应用对象的 application 模块位置告诉 gunicorn，就可以启动了。因此对于典型的 Django 项目，像这样来调用 gunicorn:</p>\n<div class=\"code-block\" data-language=\"bash\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>gunicorn<span class=\"w\"> </span>myproject.wsgi\n</code></pre></div>\n<p>这样会创建一个进程，包含了一个监听在 <code class=\"docutils literal notranslate\"><span class=\"pre\">127.0.0.1:8000</span></code> 的线程。前提是你的项目在 Python path 中，要满足这个条件，最简单的方法是在 <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> 文件所在的目录中运行这条命令。</p>\n<p>更多技巧请参考 Gunicorn 的 <a class=\"reference external\" href=\"https://docs.gunicorn.org/en/latest/deploy.html\">部署文档</a> 。</p>\n</section>","rootId":"how-to-use-django-with-gunicorn","toc":[{"title":"安装 Gunicorn","anchor":"installing-gunicorn","children":[]},{"title":"把 Django 当作普通 WSGI 应用在 Gunicorn 中运行","anchor":"running-django-in-gunicorn-as-a-generic-wsgi-application","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"操作指南","url":"/zh-hans/2.2/howto/"},{"docname":"howto/deployment/index","title":"部署 Django","url":"/zh-hans/2.2/howto/deployment/"},{"docname":"howto/deployment/wsgi/index","title":"如何使用 WSGI 进行部署","url":"/zh-hans/2.2/howto/deployment/wsgi/"}],"prev":{"docname":"howto/deployment/wsgi/index","title":"如何使用 WSGI 进行部署","url":"/zh-hans/2.2/howto/deployment/wsgi/"},"next":{"docname":"howto/deployment/wsgi/uwsgi","title":"如何用 uWSGI 托管 Django","url":"/zh-hans/2.2/howto/deployment/wsgi/uwsgi/"},"formats":{"html":"/zh-hans/2.2/howto/deployment/wsgi/gunicorn/","markdown":"/zh-hans/2.2/howto/deployment/wsgi/gunicorn.md","json":"/zh-hans/2.2/howto/deployment/wsgi/gunicorn.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/howto/deployment/wsgi/gunicorn.txt","official":"https://docs.djangoproject.com/zh-hans/2.2/howto/deployment/wsgi/gunicorn/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}