【问题标题】:virtualenv with gunicorn no working带有gunicorn的virtualenv无法正常工作
【发布时间】:2014-12-03 12:50:25
【问题描述】:

我正在开发一个 django 项目,我在 digitalocean 服务器中的实例化(droplet)中创建(通过选择一个项目)ubuntu 服务器 14.04 + django。

非常好,但是在使用 virtualenv 配置实例时 正如文件所说 http://gunicorn-docs.readthedocs.org/en/latest/deploy.html#using-virtualenv 无法识别 virtualenv,因为在安装应用程序(使用 pip 安装程序)时,例如“django framework rest”,由于没有这样的应用程序,因此无法识别并抛出 500 错误。

我也看到了这个帖子 https://www.digitalocean.com/community/questions/usinv-virtualenv-in-django-image 其中提到了配置文件的修改,您必须在其中分配在 virtualenv 中创建的新 gunicorn 的地址,但在服务重新启动时会引发错误 502:/

/* structure directory*/
/home/django
            /myproject (django)
            /envs/myapp (virtualenvs)


/* Gunicorn file */
description "Gunicorn daemon for Django project"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

respawn

setuid django
setgid django
chdir /home/django

exec gunicorn \ (**Here is where you change the url and gave 502 error)
   --name=myproject \
   --pythonpath=myproject \
   --bind=0.0.0.0:9000 \
   --config /etc/gunicorn.d/gunicorn.py \
   conf.wsgi:application

不知道为什么会出现这种情况?遇到这种情况的人可以帮我解决这个问题。

【问题讨论】:

    标签: python django virtualenv gunicorn digital-ocean


    【解决方案1】:

    我不明白你对 URL 的意思,virtualenv 与 URL 无关。您链接到的答案为您提供了解决方案:您需要使用 exec /path/to/my/virtualenv/bin/gunicorn ... 显式启动安装在 virtualenv 内的 gunicorn。

    【讨论】:

    • 设置gunicorn时,我输入了以下路由: 1- /home/django/envs/myproject/bin/gunicorn 2- envs/myproject/bin/gunicorn 3- /envs/myproject/ bin/gunicorn 后我重新启动 gunicorn 但仍然收到错误 502 只有执行更改?或更多我正在修改的文件是:/etc/init/gunicorn.conf
    • 502 是代理错误。 nginx 是否代理到:9000? nginx 和 gunicorn 错误日志显示什么?
    • 访问 xxx.xxx.xxx.101 - - [03/Dec/2014:09:39:58 -0500] "GET / HTTP/1.1" 502 583 "-" "Mozilla/5.0 ( Macintosh;Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36"
    • error 2014/12/03 09:39:58 [error] 17216#0: *1 connect() failed (111: Connection refused) while connection to upstream, client: xxx.xxx.xxx .101,服务器:_,请求:“GET / HTTP/1.1”,上游:“127.0.0.1:9000”,主机:“myproject.com”
    • myproject.com 主机仅供参考