我试图在运行Google Cloud的NGINX服务器上设置Pybossa(使用Flask构建的webapp)(以下教程,供参考)。我认为我使用的虚拟主机文件有问题,因为一旦启用它,服务器就会返回502坏网关。 Google Compute Engine VM实例正在运行Debian 8。
完整的主机文件位于:
server {
listen 80;
server_name _;
large_client_header_buffers 4 32k;
real_ip_header X-Forwarded-For;
# change that to your pybossa directory
root /home/pybossa/pybossa;
client_max_body_size 5M;
if (-f /home/pybossa/pybossa/503.html) {
return 503;
}
error_page 503 @maintenance;
location / { try_files $uri @pybossa; }
location @pybossa {
include uwsgi_params;
uwsgi_pass unix:/tmp/pybossa.sock;
}
location /static {
# change that to your pybossa static directory
alias /home/pybossa/pybossa/pybossa/themes/default/static;
autoindex on;
expires max;
}
location ~ /api/app {
rewrite ^/api/app /api/project$1 permanent;
}
location ~ /app {
rewrite ^/app(.*) /project$1 permanent;
}
error_page 503 @maintenance;
location @maintenance {
if ($uri !~ ^/static/) {
rewrite ^(.*)$ /503.html break;
}
}
}

和uwsgi配置文件:
[uwsgi]
socket = /tmp/pybossa.sock
chmod-socket = 666
chdir = /home/pybossa/pybossa
pythonpath = ..
virtualenv = /home/pybossa/pybossa/env
module = run:app
cpu-affinity = 1
processes = 2
threads = 2
stats = /tmp/pybossa-stats.sock
buffer-size = 65535

我最初设置了自己的NGINX服务器,但是没有用。现在我在由Google云部署的NGINX服务器中运行它,直到我启用`/ etc / nginx / sites-enabled /中的虚拟主机文件。
/var/log/nginx/error.log
包含以下内容:
2017/08/16 21:53:30 [alert] 439#0: *21 open socket #13 left in connection 4
2017/08/16 21:53:30 [alert] 439#0: *21 open socket #13 left in connection 4
2017/08/16 21:53:30 [alert] 439#0: aborting
2017/08/16 21:53:32 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:13 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:14 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:14 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:35 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:36 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:37 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 21:54:51 [crit] 16744#0: *1 connect() to unix:/tmp/pybossa.sock failed (2: No such file or directory) while connecting to upstream, client: 68.107.113.211, server: _, reques
t: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"

我是网络应用程序开发的新手,之前没有使用过Flask或NGINX。感谢我能得到的任何帮助。
更新:解决uwsgi未运行的问题后,现在错误日志显示
2017/08/16 23:53:27 [alert] 23944#0: *26 open socket #7 left in connection 3
2017/08/16 23:53:27 [alert] 23944#0: aborting
2017/08/16 23:53:30 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:53:30 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:53:31 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:53:31 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:53:31 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:54:29 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"
2017/08/16 23:54:30 [error] 24536#0: *1 connect() to unix:/tmp/pybossa.sock failed (111: Connection refused) while connecting to upstream, client: 68.107.113.211, server:
_, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/pybossa.sock:", host: "35.184.197.200"

答案 0 :(得分:0)
日志说没有这样的文件或目录是因为您没有在Nginx config
中设置套接字,尝试添加它,如下所示:
location / {
proxy_pass http://unix:/tmp/pybossa.sock
答案 1 :(得分:0)
检查uwsgi错误日志。它应该说,为什么它失败或返回500.另外,仔细检查是否使用适当的权限创建了套接字,因此nginx可以连接到它。