python那点技术网页前端后台技巧(CSS+HTML)《Django By Example》

Nginx+uwsgi问题锦集

2019-05-20  本文已影响1人  不爱去冒险的少年y

问题一

upstream timed out (110: Connection timed out) while reading response header from upstream
2019/05/20 13:50:59 [error] 31775#0: *281375 upstream timed out (110: Connection timed out) while reading response header from upstream, 
client: 客户端端口, server: 服务器端口, request: "POST /supplier/deviceTestData/ HTTP/1.1", 
upstream: "uwsgi://unix:/etc/uwsgi/uwsgi.sock", host: "请求端口"

nginx默认的设置时间是60s,如果你的链接时间超过这个了,那必须指明具体提时间。这里官方说最好不要超过75s,那就要看具体实现的水平能否控制在这个范围内了。因为我在这里爬坑,并不想去优化代码,所以设置600s足够。

解决:

在server{} 中的添加
uwsgi_send_timeout 600; # 指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间。
uwsgi_connect_timeout 600; # 指定连接到后端uWSGI的超时时间。
uwsgi_read_timeout 600; # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
然后重启nginx
systemctl restart nginx.service

server {
 # 这个server标识我要配置了
        listen 80;
 # 我要监听那个端口
        server_name 172.30.201.113 ;
 # 你访问的路径前面的url名称 
        access_log /var/log/nginx/access.log main;
# Nginx日志配置
        charset utf-8;
 # Nginx编码
        gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
# 支持压缩的类型
        client_max_body_size 20m;
        error_page 404 /404.html;
# 错误页面
        error_page 500 502 503 504 /50x.html;
# 错误页面

# 指定项目路径uwsgi
        location / {
# 这个location就和咱们Django的url(r'^admin/', admin.site.urls),
                include uwsgi_params;
 # 导入一个Nginx模块他是用来和uWSGI进行通讯的
                        # 注意这儿,一般这三个配套修改
            uwsgi_send_timeout 600;        # 指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间。
            uwsgi_connect_timeout 600;   # 指定连接到后端uWSGI的超时时间。
            uwsgi_read_timeout 600;        # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
 # 设置连接uWSGI超时时间
                uwsgi_pass unix:/etc/uwsgi/uwsgi.sock;
 # 指定uwsgi的sock文件所有动态请求就会直接丢给他
        }

# 指定静态文件路径
        location /static/ {
                alias /appdata/tdms/tdms/static/;
                index index.html index.htm;
        }
}

如果你使用的不是uwsgi,那么你就要注意了,你应该在nginx找到对应的nginx模块介绍。
例如你使用nginx只是作为反向代理,那么你修改的这个时间应该对应调整为:

        # 注意这儿,一般这三个配套修改
        proxy_send_timeout 600;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;

例如你使用的是fastcgi, 那么你修改的这个时间应该对应调整为:

# 注意这儿,一般这三个配套修改
        fastcgi_send_timeout 600;
        fastcgi_connect_timeout 600;
        fastcgi_read_timeout 600;

以此类推。

问题一

2019/05/20 14:00:46 [error] 13329#0: *10664 upstream prematurely closed connection while reading response header from upstream,
2019/05/20 14:00:46 [error] 13329#0: *10664 upstream prematurely closed connection while reading response header from upstream, 
client: 172.30.244.40, server: 172.30.201.113, request: "POST /cycle/get_raw_data/ HTTP/1.1", 
upstream: "uwsgi://unix:/etc/uwsgi/uwsgi.sock:", host: "172.30.201.113", referrer: "http://localhost:8080/"
上一篇 下一篇

猜你喜欢

热点阅读