0
votes

I am trying to deploy a django instance to ec2 . I am using a combination of nginx and gunicorn to achieve that. I got the nginx isntance and gunicorn to start correctly and I am able to get my instance running. But when i try to upload an image to the database on my application I run into this error in my gunicorn error.log :

connect-failed-111-connection-refused-while-connecting-to-upstream

Also all my api calls from the front end to the database return a 500 internal server in the console. My nginx.conf looks like

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

And my sites-enabled/default file as

upstream app_server_djangoapp {
server 127.0.0.1:8000 fail_timeout=0;

}

server { #EC2 instance security group must be configured to accept http connections over Port 80 listen 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;
    }
}

}

I tried most of the things people talked about - adding right permissisons to the folders. Changing localhost to 127.0.0.1 etc. I am relatively new to this topic so any help would be much appreciated!

Thank you

1

1 Answers

0
votes

I would suggest to change default to this :

upstream app_server_djangoapp {
server 127.0.0.1:8000 max_fails=3 fail_timeout=50;
keepalive 512;
}

- remove

keepalive_timeout 5;

- why do u have two location / blocks ?

    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;
    }
}