【问题标题】:Amazon AWS - Gunicorn Starts on BootAmazon AWS - Gunicorn 在启动时启动
【发布时间】:2016-11-08 21:06:23
【问题描述】:

尝试在 Amazon AWS 上部署 gunicorn 自动启动(供参考,以及 Python 的 TDD here)。

运行时使用 gunicorn 可以很好地部署站点:

../virtualenv/bin/gunicorn --bind \ unix:/tmp/mysite.com.socket.myapp.wsgi:application

但是当尝试实现 gunicorn 以启动启动时,即运行为: sudo start gunicorn-mysite.com ,得到 '502 Bad Gateway(nginx)'。

一些事情:

  1. 运行 EC2 Amazon AWS
  2. gunicorn 版本 = 1.8

/etc/init/gunicorn-mysite.com.conf

description "Gunicorn server for mysite.com"

start on net-device-up

stop on shutdown

respawn

setuid ubuntu

chdir /home/ubuntu/sites/mysite.com/source

exec ../virtualenv/bin/gunicorn \ 
--bind unix:/tmp/mysite.com.socket \ 
myapp.wsgi:application

日志显示如下:

/var/log/upstart **

usage: gunicorn [OPTIONS][APP_MODULE]
gunicorn: error: No application module specified

**

/var/log/nginx

...[error] 6282#0 : * connect() to unix:/tmp/mysite.com.socket failed (111: Connection refused) while connecting to upstream client 10.10.100.100, server: mysite.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/mysite.com.socket:/", host: "mysite.com"

我正在使用以下命令运行 gunicorn:

(virtualenv)ubuntu@/source$ sudo service nginx restart
(virtualenv)ubuntu@/source$ sudo starg gunicorn-mysite.com

不知道为什么我的网关会变差——非常感谢任何帮助!

【问题讨论】:

    标签: python amazon-web-services nginx gunicorn gateway


    【解决方案1】:

    在您的代码中:

    exec ../virtualenv/bin/gunicorn \ 
    --bind unix:/tmp/mysite.com.socket \ 
    myapp.wsgi:application
    

    myapp.wsgi替换为你的入口python文件的名称,将application替换为你的python文件中定义的名称。

    例如,如果/home/ubuntu/sites/mysite.com/source 中有一个run.py,如下所示:

    from src import app
    
    if __name__ == '__main__':
        app.run()
    

    你可以改变你的配置如下:

    exec ../virtualenv/bin/gunicorn \ 
    --bind unix:/tmp/mysite.com.socket \ 
    run:app
    

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 2023-03-14
      • 2017-03-19
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2016-06-18
      • 2020-05-26
      相关资源
      最近更新 更多