【发布时间】:2017-02-09 11:22:49
【问题描述】:
我正在尝试将 django 实例部署到 ec2 。我正在使用 nginx 和 gunicorn 的组合来实现这一点。我让 nginx istance 和 gunicorn 正确启动,并且我能够让我的实例运行。但是当我尝试将图像上传到我的应用程序的数据库时,我在 gunicorn error.log 中遇到了这个错误:
connect-failed-111-connection-refused-while-connecting-to-upstream
此外,我从前端到数据库的所有 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 实例安全组必须配置为接受端口 80 上的 http 连接 听 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;
}
}
}
我尝试了人们谈论的大部分内容 - 为文件夹添加正确的权限。将 localhost 更改为 127.0.0.1 等。我对这个主题比较陌生,所以非常感谢任何帮助!
谢谢
【问题讨论】:
标签: django nginx amazon-ec2