python - centos7+django+uwsgi+nginx访问报错

查看:177
本文介绍了python - centos7+django+uwsgi+nginx访问报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

报错如下:

2016/05/13 19:02:40 [error] 11057#0: *162 upstream prematurely closed connection while reading 
response header from upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET 
/poweredby.png HTTP/1.1", upstream: "uwsgi://127.0.0.1:8003", host: "xxx.xxx.xxx.xxx:8000", 
referrer: "http://xxx.xxx.xxx.xxx:8000/"

uwsgi 配置如下:

[uwsgi]
socket = 127.0.0.1:8003
touch-reload=/myblog/reload

processes = 2
threads = 4
vacuum = true

nginx 配置如下:

 server {
        listen       8000;
        server_name  xxx.xxx.xxx.xxx;
        root         /usr/share/nginx/html;
        access_log /logs/access.log;
        error_log /logs/error.log;

        charset     utf-8;

        # Load configuration files for the default server block.

        location / {
            include  /etc/nginx/uwsgi_params;
            uwsgi_pass  127.0.0.1:8003;
            client_max_body_size 35m;
            uwsgi_param UWSGI_SCRIPT myblog.wsgi;
            uwsgi_param UWSGI_CHDIR /myblog;
        }
        location /media  {
            alias /path/to/project/media;
        }

        location /static {
            alias /path/to/project/static;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

views.py 文件内容

#coding:utf-8
from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse(u"Hello World!!")

搞了一天了,死活连不上, uwsgi8003 端口正常访问, nginx 代理 8000 端口连不上,端口已经开放,防火墙已经关闭,求解,感激不尽!

解决方案

upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # 建议用sock文件
    server 127.0.0.1:8003;
}
...
location / {
    uwsgi_pass  django;
    include     /path/to/your/mysite/uwsgi_params;
}
...

而且你的uWSGI的配置文件也有点奇怪,不知道你是哪里看的教程,反正uWSGI + Nginx + Django完整配置过程看【Setting up Django and your web server with uWSGI and nginx】人家uWSGI官方文档就好了。

通信过程:
客户端访问8000 ——> Nginx -8003-> uWSGI ——> Django,按着官方文档里的步骤来,它会按过程一步一步配置并验证,哪一环出错了一目了然。

这篇关于python - centos7+django+uwsgi+nginx访问报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆