3

我是配置服务器的新手。我想配置我的 Amazon-EC2 实例。我是按照这个文档配置的。http://www.soundrenalin.com/about

但是,当我单击 url 时,502 Bad Gateway遇到了错误。我的项目位于此路径:/home/ubuntu/dsn/app. 文件夹树是
/home/ubuntu/dsn

app/
    app.py
    static/
    templates/
    themes/
bin/
build/
include/
lib/
local/
run.py


这是我的 nginx 配置(/etc/nginx/sites-available/default):

server {
        listen   80; 

        root /home/ubuntu/dsn/app
        index index.html index.htm;

        server_name localhost;
        location / { try_files $uri @app; }
        location @app {
             include uwsgi_params;
             uwsgi_pass unix:/tmp/uwsgi.sock;
        }
}

这是我的uwsgi.ini文件:

[uwsgi]
     chdir = /home/ubuntu/dsn/
     uid = www-data
     gid = www-data
     chmod-socket = 666
     socket = /tmp/uwsgi.sock
     module = run
     virtualenv = /home/ubuntu/dsn/   

另一件事是:
当我运行命令tail -f /var/log/nginx/error.log结果是:

2013/06/09 15:58:11 [error] 5321#0: *1 connect() to unix:/tmp/uwsgi.sock failed (111: Connection refused) while connecting to upstream, client: <myip>, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "54.218.14.213"

我该如何解决这个问题?谢谢。

4

2 回答 2

1

它可能是以下情况之一:

  1. 您的 UWSGI 套接字不在 /tmp/uwsgi.sock
  2. uwsgi 或 www-data 用户无权在 /tmp 目录中创建 uwsgi.sock。

如果你在 Ubuntu 12.04 上安装了 Uwsgi,配置文件应该位于:

/usr/share/uwsgi/conf/default.ini

这是该文件中的默认套接字配置:

# bind to UNIX socket at /run/uwsgi/<confnamespace>/<confname>/socket
socket = /run/uwsgi/%(deb-confnamespace)/%(deb-confname)/socket

您应该创建一个与我的类似的特定于应用程序的配置文件。我可以确认它在虚拟环境中工作。

sudo vim /etc/uwsgi/apps-available/your-app.ini

your-app.ini 的内容:

[uwsgi]
base = /home/nick/your-app.com

#location of the flask application file
file = /home/nick/your-app.com/main.py

#uwsgi varible only, does not relate to your flask application
callable = app

#uwsgi plugins
plugins = http,python

#to create within a virtual environment
home = %(base)/venv

pythonpath = %(base)
socket = /tmp/%n.sock
logto = /var/log/uwsgi/%n.log
workers = 3

要启用,您需要符号链接并重新启动 nginx。

#make sure that any user to write to the /tmp directory
sudo chmod 777 /tmp
sudo ln -s /etc/uwsgi/apps-available/your-app.ini /etc/uwsgi/apps-enabled/your-app.ini
sudo service uwsgi restart
于 2013-06-10T12:14:41.047 回答
-2

来自https://stackoverflow.com/a/33587478/260127

您可以使用 ubutu 的 upstart 和 uwsgi 的 --emperor 选项轻松执行 python uwsgi 应用程序。

于 2015-11-07T20:45:02.260 回答