简体   繁体   English

连接到上游时上游超时(110:连接超时)

[英]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.我想在 ubuntu 机器的 AWS ec2 实例中的端口号 8000 上部署我的 Django 网站。 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.但是在运行 Nginx 服务器后,我在浏览器中收到以下 400/Bad request 错误,并且在 Nginx 错误日志中显示如下。

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 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_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 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.最后,我从 facebook 小组中得到了答案。 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).由于我的 Nginx 服务器和我的 Django 网站在同一台机器上运行,server_name 应该是 localhost(Nginx 将访问同一网络内的网站)。 For more understandability, I'm putting the modified configuration below.为了更容易理解,我将修改后的配置放在下面。 my_site.conf 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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Scrapy,无法爬行任何页面:“ TCP连接超时:110:连接超时。” - Scrapy, can't crawl any page: “TCP connection timed out: 110: Connection timed out.” Python3 urllib.error.URLError:<urlopen error [errno 110] connection timed out> 在服务器上</urlopen> - Python3 urllib.error.URLError: <urlopen error [Errno 110] Connection timed out> on server pymysql.err.OperationalError: (2006, "MySQL server has gone away (TimeoutError(110, 'Connection timed out'))") - pymysql.err.OperationalError: (2006, "MySQL server has gone away (TimeoutError(110, 'Connection timed out'))") PyCharm 2019.3 Python 控制台 - 连接超时 - PyCharm 2019.3 Python Console - Connection timed out python中的Scrapy TCP连接超时问题 - Scrapy TCP connection timed out issue in python 在 Windows 10 系统上安装 Selenium Python 客户端时连接到 pypi.org 超时错误 - Connection to pypi.org timed out error while installing Selenium Python clients on Windows 10 system 连接超时 - 使用 sqlalchemy 访问 AWS usaspending 数据 - Connection timed out - using sqlalchemy to access AWS usaspending data TimeoutError:读取操作超时 - TimeoutError: The read operation timed out Codingbat make_bricks 在 python 中使用 while 循环超时 - Codingbat make_bricks timed out with while loop in python 安装模块时握手操作超时错误 - Handshake operation timed out error while installing modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM