简体   繁体   中英

upstream timed out (110: Connection timed out) while connecting to upstream

I wanted to deploy my Django website on port number 8000 in my AWS ec2 instance of the ubuntu machine. But after running the Nginx server, I'm getting the following 400/Bad request error in the browser, and in the Nginx error log, it's showing as follows.

upstream timed out (110: Connection timed out) while connecting to upstream, client: 23.104.74.85, server: , request: "GET / HTTP/1.1", upstream: "http://2.12.52.96:8080/", host: "2.12.52.96"

Below are my code snippets.

my_site.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/ubuntu/my_site/my_site.sock;
}

# configuration of the server
server {
    listen      8000;
    server_name 2.12.52.96;
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;

    # Django media and static files
    location /media  {
        alias /home/ubuntu/my_site/media;
    }
    location /static {
        alias /home/ubuntu/my_site/static;
    }

    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  2.12.52.96:8000; 
        include     /home/ubuntu/my_site/uwsgi_params;
    }
}

uwsgi_params

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

my_site.ini

[uwsgi]

# full path to Django project's root directory
chdir            = /home/ubuntu/my_site/
# Django's wsgi file
module           = my_site.wsgi
# full path to python virtual env
home             =  /home/ubuntu/.virtualenvs/newUser

# enable uwsgi master process
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /home/ubuntu/my_site/my_site.sock
# socket permissions
chmod-socket    = 666
# clear environment on exit
vacuum          = true
# daemonize uwsgi and write messages into given log
daemonize       = /home/ubuntu/uwsgi-emperor.log

Finally I got the answer from a facebook group. Thanks Hassan Aly Selim. Since, my Nginx server and my Django website are running on the same machine, server_name should be localhost (Nginx will access website within the same network). For more understandability, I'm putting the modified configuration below. my_site.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/ubuntu/my_site/my_site.sock;
}

# configuration of the server
server {
    listen      8000;
    server_name localhost;
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;

    # Django media and static files
    location /media  {
        alias /home/ubuntu/my_site/media;
    }
    location /static {
        alias /home/ubuntu/my_site/static;
    }

    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django; 
        include     /home/ubuntu/my_site/uwsgi_params;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM