我正在尝试将django实例部署到ec2。我正在使用nginx和gunicorn的组合来实现这一目标。我得到了nginx isntance和gunicorn正确启动,我能够让我的实例运行。但是当我尝试将图像上传到我的应用程序的数据库时,我在gunicorn error.log中遇到了这个错误:
连接失败的-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实例安全组配置为通过端口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等。我对此主题相对较新,因此非常感谢任何帮助!
谢谢
答案 0 :(得分:0)
我建议将默认值更改为:
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;
}
}