connect()失败(111:连接被拒绝),同时连接到上游,客户端
问题描述:
我想部署一个Django实例到ec2。我正在使用nginx和gunicorn的组合来实现这一点。我得到了nginx isntance和gunicorn正确启动,我能够让我的实例运行。但是,当我试图将影像上传到我的应用程序的数据库我遇到这个错误在我gunicorn error.log中:connect()失败(111:连接被拒绝),同时连接到上游,客户端
连接失败的-111连接,拒绝,同时,连接到上游
从前端到数据库的所有api调用都会在控制台中返回一个500内部服务器。 我的nginx.conf看起来像
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
include /etc/nginx/sites-available/*;
index index.html index.htm;
server {
listen 127.0.0.1:80;
listen [::]:80 default_server;
server_name 127.0.0.1;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location/{
}
# redir
而且我启用的站点 - /默认文件
upstream app_server_djangoapp {
server 127.0.0.1:8000 fail_timeout=0;
}
服务器{ #EC2实例安全组必须配置为接受HTTP连接通过80端口 听80; server_name myec2isntance.com;
access_log /var/log/nginx/guni-access.log;
error_log /var/log/nginx/guni-error.log info;
keepalive_timeout 5;
# path for static files
location /static {
alias xxxxxx;
}
location /media {
alias xxxxxx;
}
location/{
location/{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server_djangoapp;
break;
}
}
}
我想大多数人津津乐道的事情 - 将右permissisons的文件夹。改变本地主机为127.0.0.1等我对这个主题相对较新,所以任何帮助将不胜感激!
谢谢
答
我会建议默认改成这样:
upstream app_server_djangoapp {
server 127.0.0.1:8000 max_fails=3 fail_timeout=50;
keepalive 512;
}
- 删除
keepalive_timeout 5;
- 为什么ü有两个位置/块?
location/{
location/{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server_djangoapp;
break;
}
}
哎呀!没有注意到双重位置块。我摆脱了它。现在我没有看到日志中的任何内容,但每次我从前端执行POST调用时,都会看到500内部服务器错误。 –
这是进步。当你运行Django的开发服务器时,跟踪是什么?另外,如果上传时间超过30秒,Gunicorn将超时。你需要在你的gunicorn命令中使用'--timeout 120'(2分钟) –