我有Django的应用程序(基于夹层)。
我的nginx conf看起来像:
upstream myhost { server 127.0.0.1:8000; } server { listen 80; server_name www.myhost.ru myhost.ru; client_max_body_size 10M; keepalive_timeout 15; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Protocol $scheme; proxy_pass http://myhost; } location /static/ { root /home/myhost/virtualenvs/myhost/project; access_log off; log_not_found off; } location /robots.txt { root /home/myhost/virtualenvs/myhost/project/static; access_log off; log_not_found off; } location /favicon.ico { root /home/myhost/virtualenvs/myhost/project/static/img; access_log off; log_not_found off; } }
在浏览器中,我看到“内部服务器错误”。
我在/var/log/nginx/errir.log中看到以下错误:
2013/04/20 12:24:57 [warn] 11479#0: *1 upstream sent more data than specified in "Content-Length" header while reading upstream, client: 89.189.170.4, server: www.rureads.ru, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "myhost.ru" 2013/04/20 12:38:14 [warn] 11481#0: *19 upstream sent more data than specified in "Content-Length" header while reading upstream, client: 89.189.170.4, server: www.rureads.ru, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "myhost.ru"
什么可能导致这个问题? 如何解决这个问题?
好吧,所以我在这方面挣扎了很长时间。 就我而言,我的django应用程序(当使用django开发服务器时没有显示自己)潜伏着夹层的导入错误。 出于某种原因(也许是一个炮弹漏洞?),这个导入错误没有被显示在浏览器中(即使DEBUG = True)或被gunicornlogging。 相反,我只是从nginx得到一个“内部服务器错误”,而nginx错误日志中的“上游发送了更多指定的数据…”消息。 gunicorn日志只logging了请求,好像一切正常。 鉴于没有任何具体的错误logging在任何地方,我花了很长时间才发现导入错误,并修复它。 就我而言,我只能通过在设置中注释掉所有MIDDLEWARE_CLASSES并设置DEBUG = True,才能显示出django错误页面。 这显示了我固定的导入错误。 然后,我重新启用MIDDLEWARE_CLASSES,重新启动了gunicorn工作者,一切正常!
希望这可以节省一些时间。