我遇到了以下问题,但我怀疑这是一个配置问题。我正在使用的DJANGO应用程序是开源的(来自GitHub)。服务组件是DJANGO,NGINX和GUNICORN。
点击网站的user-profile
页面会产生以下网页错误(所有其他网站链接显示正常 - 没有问题):
Internal Error!
Sorry about that.
A detailed error report has been generated and has been sent to the managers.
If the problem persists please contact the site owners.
在封面下方,看起来错误电子邮件也是由以下主题构建的:
[Django] ERROR (EXTERNAL IP): Internal Server Error: /u/1/
同样,我没有遇到任何产生此问题的其他网站链接(但我刚开始这个)。
查看日志,这里有更多信息(我在example.com
和93.184.216.34
中替换了实际的主机/域名和IP地址),主机/域名及其IP地址在NGINX和ALLOWED_HOSTS(live.deploy设置文件)中指定。 gunicorn使用UNIX DOMAIN SOCKET与NGINX进行通信。
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: [Django] ERROR (EXTERNAL IP): Internal Server Error: /u/1/
From: noreply@lvh.me
To: admin@lvh.me
Date: Tue, 26 Sep 2017 17:03:10 -0000
Message-ID: <20170926170310.692.19616@example.com>
Traceback (most recent call last):
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/core/handlers/base.py", line 137, in get_response
response = response.render()
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/response.py", line 80, in rendered_content
template = self.resolve_template(self.template_name)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/response.py", line 56, in resolve_template
return loader.select_template(template)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 180, in select_template
return get_template(template_name)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 138, in get_template
template, origin = find_template(template_name)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 127, in find_template
source, display_name = loader(name, dirs)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 43, in __call__
return self.load_template(template_name, template_dirs)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 49, in load_template
template = get_template_from_string(source, origin, template_name)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader.py", line 149, in get_template_from_string
return Template(source, origin, name)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 125, in __init__
self.nodelist = compile_string(template_string, origin)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 153, in compile_string
return parser.parse()
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader_tags.py", line 215, in do_extends
nodelist = parser.parse()
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/loader_tags.py", line 190, in do_block
nodelist = parser.parse(('endblock',))
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 278, in parse
compiled_result = compile_func(self, token)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/defaulttags.py", line 942, in do_if
nodelist = parser.parse(('elif', 'else', 'endif'))
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 276, in parse
self.invalid_block_tag(token, command, parse_until)
File "/home/www/.virtualenvs/biostar/lib/python2.7/site-packages/django/template/base.py", line 331, in invalid_block_tag
(command, get_text_list(["'%s'" % p for p in parse_until])))
TemplateSyntaxError: Invalid block tag: 'endblock', expected 'elif', 'else' or 'endif'
<WSGIRequest
path:/u/1/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{'biostar2': '8fatnvziwin0wg1mf4ufeoxkg7c6bkt1',
'csrftoken': 'Zk99UboOd7VXjCUzRhuvOwRJrywQRbNr'},
META:{u'CSRF_COOKIE': u'Zk99UboOd7VXjCUzRhuvOwRJrywQRbNr',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.9',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=Zk99UboOd7VXjCUzRhuvOwRJrywQRbNr; biostar2=8fatnvziwin0wg1mf4ufeoxkg7c6bkt1',
'HTTP_DNT': '1',
'HTTP_HOST': 'example.com',
'HTTP_REFERER': 'http://example.com/user/list/',
'HTTP_UPGRADE_INSECURE_REQUESTS': '1',
'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.29 Safari/537.36',
'HTTP_X_FORWARDED_FOR': '93.184.216.34',
'PATH_INFO': u'/u/1/',
'QUERY_STRING': '',
'RAW_URI': '/u/1/',
'REMOTE_ADDR': '',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'example.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SOFTWARE': 'gunicorn/19.7.1',
'gunicorn.socket': <socket._socketobject object at 0x7f4a14d12600>,
'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f4a159bac90>,
'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
'wsgi.input': <gunicorn.http.body.Body object at 0x7f4a14cfce10>,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>
nginx.conf
upstream biostar_server {
server unix:/home/www/sites/biostar-central/live/rootfs/var/run/biostar.gunicorn.socket fail_timeout=0;
}
# When no server names match then crash out.
server {
return 404;
}
server {
listen 80;
client_max_body_size 5M;
server_name 93.184.216.34 example.com;
keepalive_timeout 25s;
# Path for static files.
root /home/www/sites/biostar-central/live/export/;
access_log /home/www/sites/biostar-central/live/rootfs/var/log/biostar.nginx.access.log;
error_log /home/www/sites/biostar-central/live/rootfs/var/log/biostar.nginx.error.log;
location = /favicon.ico {
alias /home/www/sites/biostar-central/live/export/static/favicon.ico;
}
location = /sitemap.xml {
alias /home/www/sites/biostar-central/live/export/static/sitemap.xml;
}
location = /robots.txt {
alias /home/www/sites/biostar-central/live/export/static/robots.txt;
}
location /static/ {
autoindex on;
expires max;
add_header Pragma public;
add_header Cache-Control "public";
access_log off;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://biostar_server;
proxy_buffering off;
}
}
# Redirect domains.
# Commented out to simplify troubleshooting.
#server {
# listen 80;
# Redirect to www.
#server_name example.com;
#rewrite ^(.*) http://www.example.com$1 permanent;
# Redirect to non-www.
#server_name www.example.com;
#return 301 $scheme://example.com$request_uri;
#}
有什么想法吗? 我尝试了很多东西,但显然不是正确的事情。 =:)
提前谢谢!
修改: 请注意,GitHub software非常稳定并且已经运行了一些网站很长一段时间,所以如果问题是模板语法相关,我会期望将更正检入GitHub到现在为止(因为开发人员非常好,并且在代码和网站的基础上)。但是假装没有将更正检查回GitHub,那么它的采用者将不得不在实现时修复任何语法错误。不幸的是,我不是DJANGO开发人员,所以假设它是一个模板语法问题,任何有关如何跟踪错误文件和语法的指针都表示赞赏。但同样,这是稳定的软件。谢谢!
修改-2: 设置DEBUG = True时(以及重新访问的URL),这是有问题URL的粘贴网址:https://pastebin.com/EG1UTdmA
答案 0 :(得分:0)
这是我正在使用的开源软件中的一个错误(由错误的GitHub合并引起)。开发人员迅速解决了问题,并将更新发布在GitHub上。
但值得注意的是,我要感谢@ aamir-adnan(上面的评论者),他突然跳过这个问题,试图找到罪魁祸首。上面没有看到部分工作,因为它是通过StackOverflow聊天会话发生的。所以,谢谢Aamir!