简体   繁体   English

Google Cloud Compute Engine上的Flask + NGINX + UWSGI提供了502错误的网关

[英]Flask+NGINX+UWSGI on Google Cloud Compute Engine gives 502 bad gateway

I'm trying to set up Pybossa (webapp built with Flask) on an NGINX server running on Google Cloud (following this tutorial, for reference). 我正在尝试在Google Cloud上运行的NGINX服务器上设置Pybossa(使用Flask构建的web应用程序)(此教程仅供参考)。 I think there is something wrong with the virtual host file I'm using since as soon as I enable it the server returns 502 bad gateway. 我认为我正在使用的虚拟主机文件有问题,因为一旦启用它,服务器就会返回502错误的网关。 The Google Compute Engine VM instance is running Debian 8. Google Compute Engine VM实例正在运行Debian 8。

The full hosts file is here: 完整的主机文件在这里:

 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; } } } 

And the uwsgi config file: 和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 

I had initially set up my own NGINX server, which didn't work. 我最初设置了自己的NGINX服务器,但该服务器无法正常工作。 Now I'm running it in an NGINX server deployed by Google cloud, which works fine until I enable the virtual hosts file in `/etc/nginx/sites-enabled/. 现在,我在由Google云部署的NGINX服务器中运行它,在我在`/ etc / nginx / sites-enabled /中启用虚拟主机文件之前,它可以正常工作。

The /var/log/nginx/error.log contains the following: /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" 

I'm new to web app development and haven't used Flask or NGINX before. 我是Web应用程序开发的新手,以前没有使用过Flask或NGINX。 Appreciate any help I can get. 感谢我可以获得的任何帮助。

UPDATE: After fixing the issue where uwsgi wasn't running, now error log says 更新:修复了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" 

The log say No such file or directory is because you don't have set up the socket in your Nginx config , try to add it, something like this: 日志中说没有这样的文件或目录是因为您尚未在Nginx config设置套接字,请尝试添加它,如下所示:

 location / {
            proxy_pass http://unix:/tmp/pybossa.sock

Check the uwsgi error logs. 检查uwsgi错误日志。 It should say, why it's failing or returning 500. Also, double check that the socket is created with the proper privileges, so nginx can connect to it. 它应该说出为什么还是失败或返回500。此外,还要仔细检查套接字是使用适当的权限创建的,以便nginx可以连接到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM