uWSGI nginx 错误:连接到上游时 connect() 失败(111:连接被拒绝)
我在 nginx(http://52.xx.xx.xx/),日志简单地说:
I'm experiencing 502 gateway errors when accessing my IP on nginx(http://52.xx.xx.xx/), the logs simply says this:
2015/09/18 13:03:37 [错误] 32636#0:*1 connect() 失败(111:连接被拒绝),同时连接到上游,客户端:xx.xx.xx.xx,服务器:xx.xx.xx.xx,请求:GET/HTTP/1.1",上游:uwsgi://127.0.0.1:8000",主机:xx.xx.xx.xx"
2015/09/18 13:03:37 [error] 32636#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "xx.xx.xx.xx"
我的 nginx.conf 文件
my nginx.conf file
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name xx.xx.xx.xx; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /home/ubuntu/test_django/nginx_access.log;
error_log /home/ubuntu/test_django/nginx_error.log;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/test_django/static/media/; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/test_django/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/test_django/uwsgi_params; # the uwsgi_params file you installed
}
}
nginx.conf 文件有什么问题吗.....如果我使用默认 conf 那么它就可以工作了.
Is there anything wrong with nginx.conf file.....if i use default conf then it is working.
我通过更改 uwsgi.ini 中的 socket 配置解决了从socket = 127.0.0.1:3031
,到socket = :3031
.当我在一个 Docker 容器中运行 nginx 而在另一个容器中运行 uWSGI 时,我遇到了这个问题.如果您使用命令行启动 uWSGI,则执行 uwsgi --socket :3031
.
I resolved it by changing the socket configuration in uwsgi.ini
from socket = 127.0.0.1:3031
, to socket = :3031
. I was facing this issue when I ran nginx in one Docker container and uWSGI in another. If you are using command line to start uWSGI then do uwsgi --socket :3031
.
希望这有助于在使用 Docker 部署 Django 应用程序期间遇到同样问题的人.
Hope this helps someone stuck with the same issue, during deployment of a Django application using Docker.