注销时出现Django HttpResponse内部服务器错误

时间:2014-10-03 12:54:27

标签: python django nginx uwsgi

我的Django应用程序(在uwsginginx的vitrualenv中启动了JSON数据的JQuery请求):

$.getJSON( url, function( data ) {
    var obl  = "/raj/?raj=" + data.id;
    $.getJSON( obl, function( raj_data ) {
        ...
        } );
    } );

和相应的观点:

def rcoato(request):
    response_data = SprRegion.objects.values('id').get(Q(id=request.GET['region']))
    response_data = json.dumps(response_data)
    return HttpResponse(response_data, content_type='application/javascript')

它工作正常,JSON数据返回,但仅当我通过SSH登录时。 我用以下方式开始申请:

source virtualenv/bin/activate
uwsgi --xml /home/rino/sites/centre/uwsgi.xml & 

当我退出时(使用setopt no_hupsetopt no_checkjobs),我的应用程序部分工作 - HTML页面正在呈现,静态文件正在处理,但对/raj/?raj=...的请求引发内部服务器错误500

我的nginx.conf

server {
       listen 8081;
       server_name localhost;
       access_log /var/log/nginx/nginx_centre_access.log;
       error_log /var/log/nginx/nginx_centre_error.log;

       location /static {    
           autoindex on;    
           alias /home/rino/sites/centre/centre/static/;    
       }

       location / {
           uwsgi_pass 127.0.0.1:3031;
           include /home/rino/sites/centre/uwsgi_params;
       }
}

uwsgi config:

<uwsgi>
  <socket>127.0.0.1:3031</socket>
  <processes>5</processes>
  <pythonpath>/home/rino/sites/centre</pythonpath>
  <chdir>/home/rino/sites/centre/centre</chdir>
  <wsgi-file>/home/rino/sites/centre/centre/wsgi.py</wsgi-file>
  <pidfile>/tmp/centre-master.pid</pidfile>
  <plugin>python3</plugin>
  <max-requests>5000</max-requests>
  <harakiri>40</harakiri>
  <master>true</master>
  <threads>2</threads>
</uwsgi>
在上述注销和查询请求后

cat nginx_centre_error.log | tail

2014/10/03 07:34:46 [error] 20657#0: *296 connect() failed (111: Connection refused) 
while connecting to upstream, client: 176.100.173.177, server: localhost, request: "GET 
/settler/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "myhost.com:8081",   
referrer:  "http://myhost.com/settlersmain/"

2014/10/03 07:56:55 [error] 20657#0: *335 connect() failed (111: Connection refused) 
while connecting to upstream, client: 176.100.173.177, server: localhost, request: 
"GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "myhost.com:8081"
2014/10/03 08:23:33 [error] 20657#0: *367 open()

感谢您的帮助!

UPD:我将localhostserver_name中的nginx.conf替换为服务器IP地址,但问题仍然存在。

1 个答案:

答案 0 :(得分:1)

根据您的日志,您有(111: Connection refused)错误,这意味着在关闭ssh连接后uwsgi进程被终止。

您可以尝试this instruction使用nohup

uWSGI可以选择daemonize。这是一种更好的方法,uWSGI将处理从控制台分离。

但我建议您使用supervisord之类的东西来运行uWSGI。或者您可以使用系统的init.d脚本或Upstart