我想用Nginx部署一个Flask和uwsgi应用程序,一切正常,我可以让我的应用程序在我的域上工作: test.example.com:8080 : test.example.com:8080 。
问题是我不能使其在默认端口80下工作,当我尝试浏览test.example.com时,从Nginx中获得以下错误消息:
2016/09/02 10:21:29 [error] 2947#2947: *3 no live upstreams while connecting to upstream, client: 75.xxx.xxx.136, server: test.example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://localhost", host: "test.example.com", referrer: "http://test.example.com/"
这是我的uwsgi命令:
uwsgi --socket 8080 --chdir /var/www/test.example.com --protocol=http --module myapp:app
这是我的Nginxconfiguration:
server { listen 80; root /var/www/test.example.com; server_name test.example.com; location / { include uwsgi_params; uwsgi_pass 0.0.0.0:8080; uwsgi_param SCRIPT_NAME /myapp; } }
Nginx不能把我的服务器的stream量从80端口传给8080端口,我不知道为什么。
你的uwsgi命令行是错误的。 通过检查/var/www/test.example.com下是否有名为8080的文件套接字进行确认。 如果在那里,你已经混合了TCP和UNIX套接字。
而且, – 协议--protocol http意味着你应该使用HTTP协议访问uwsgi,而不是uwsgi自己的,nginx也支持。 删除该选项,或使用proxy_pass而不是uwsgi_pass 。
正确的命令行是:
uwsgi --socket :8080 --chdir /var/www/test.example.com --module myapp:app
为了提高安全性,您可能还需要指定站点本地IP以供uwsgi监听,所以使用例如127.0.0.1:8080而不是:8080 。
还有一种方法是使用UNIX套接字,而不是通过为uwsgi命令行指定套接字path来监听tcp / 8080,并在nginxconfiguration中使用uwsgi_pass unix:/file/path/passed/to/socket 。 这会更安全一些,因为你可以通过目录的权限控制套接字的访问权限,限制本地用户造成伤害的能力。