2012-03-22 50 views
0

我有一個應用程序在Apache2上工作。我希望切換到uwsgi。 部署後,我面臨看中了問題,就像是隨機的錯誤:wsgi django和隨機500

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__ 
30928-    response = self.get_response(request) 
30929-  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 169, in get_response 
30930-    response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) 
30931-  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception 
30932-    return callback(request, **param_dict) 
30933-  File "/var/www/fancy_site/releases/current/fancy_site/utils/views.py", line 699, in server_error 
30934-    'GIGYA_API_KEY':settings.GIGYA_API_KEY, 
30935-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 123, in render 
30936-    return self._render(context) 
30937-  File "/usr/local/lib/python2.6/dist-packages/django/test/utils.py", line 60, in instrumented_test_render 
30938-    return self.nodelist.render(context) 
30939-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 744, in render 
30940-    bits.append(self.render_node(node, context)) 
30941-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 757, in render_node 
30942-    return node.render(context) 
30943-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 105, in render 
30944-    compiled_parent = self.get_parent(context) 
30945-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 102, in get_parent 
30946-    return get_template(parent) 
30947-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 157, in get_template 
30948-    template, origin = find_template(template_name) 
30949-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 134, in find_template 
30950-    source, display_name = loader(name, dirs) 
30951-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 42, in __call__ 
30952-    return self.load_template(template_name, template_dirs) 
30953-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 48, in load_template 
30954-    template = get_template_from_string(source, origin, template_name) 
30955-  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 168, in get_template_from_string 
30956-    return Template(source, origin, name) 
30957-  File "/usr/local/lib/python2.6/dist-packages/debug_toolbar/panels/template.py", line 37, in new_template_init 
30958-    old_template_init(self, template_string, origin, name) 
30959-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 108, in __init__ 
30960-    self.nodelist = compile_string(template_string, origin) 
30961-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 136, in compile_string 
30962-    return parser.parse() 
30963-  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py", line 239, in parse 
30964-    compiled_result = compile_func(self, token) 
30965-  File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py", line 1054, in load 
30966-    (taglib, e)) 
30967-django.template.base.TemplateSyntaxError: 'sso_token' is not a valid tag library: Template library sso_token not found, tried django.templatetags.sso_token,django.contrib.admin.templatetags.sso_token,django.contrib.webdesign.templatetags.sso_token,paging.templatetags.sso_token,sentry.templatetags.sso_token,tinymce.templatetags.sso_token,pagination.templatetags.sso_token,rosetta.templatetags.sso_token,flatblocks.templatetags.sso_token,oembed.templatetags.sso_token,debug_toolbar.templatetags.sso_token,memcache_status.templatetags.sso_token,mailchimp.templatetags.sso_token 

Django的給我類似的異常像郵件:沒有模塊名稱的意見 - 這是ofcourse不正確的,因爲這個應用程序的工作在Apache兩年以來: )

我不知道問題所在 - 我知道我無法在我的舞臺env - 這是一臺克隆生產機器上重現它。據我所知這不是代碼依賴錯誤或應用程序問題。

在procution我使用當前配置:

我使用: django的1.3.1 uWSGI 1.1 nginx的1.0.12-1〜dotdeb.0 蟒2.6 的Debian 6.0.3 2× QC至強E5540與8 GB內存條

這些機器由物理負載平衡器支持託管公司。

nginx的CFG:

server { 
 listen 80; 
       server_name www.fancy_site.fancy_domain fancy_site.fancy_domain 
       server_name_in_redirect off; 
       access_log /path/to/file.log; 

       if ($host = 'fancy_site') { 
           rewrite ^/(.*)$ http://www.fancy_site.fancy_domain/$1 permanent; 
       } 

       location /media/ { 
           alias /path/to/media/; 
           expires max; 
       } 

       location  /site_media/ { 
           alias /path/to/media/; 
           expires max; 
       } 

       location /static/ { 
           alias   /path/to/static/; 
           expires max; 
       } 

       gzip  on; 
       gzip_http_version 1.0; 
       gzip_vary on; 
       gzip_comp_level 3; 
       gzip_proxied any; 
       gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 
       gzip_buffers 16 8k; 
       gzip_disable 「MSIE [1-6].(?!.*SV1)」; 

       location/{ 
           uwsgi_pass unix://path/to/uwsgi.socket; 
           include uwsgi_params; 
       } 

} 

uWSGI CFG:

prefix = /path/to/prod_direcotry 
master = true 
processes = 80 
uid = fancy_application 
gid = www-data 
memory-report = true 
max-requests = 800 
stdout_logfile = /path/to/uwsgi.log 
daemonize = /path/to/uwsgi.log 
redirect_stderr = true 
logfile-chown=www-data 
socket = /path/to/uwsgi.socket 
chdir = /path/to/application_direcotry 
pythonpath = /path/to/to_current_release_of_application 
env = DJANGO_SETTINGS_MODULE=application_direcotry.settings 
module = django.core.handlers.wsgi:WSGIHandler() 
touch-reload = %(prefix)/touch_to_restart 

我想問你的社區,如果有人有相同或相似的問題。也許有人解決並希望分享如何?

問候 盧卡斯

回答

1

除非你看到其他錯誤,你應該試着去理解錯誤你得到的最有可能是真正的原因是什麼。

你的情況你缺少一個templatetags庫(名爲sso_token)。這很可能意味着您未能在生產計算機上安裝依賴項,或者您的INSTALLED_APPS在生產和開發之間不同,而您錯過了提供該庫的應用程序。

這很可能不是由您的部署造成的,更可能是由您的生產環境和開發環境之間的不連續性引起的。

+0

嘿,thx回答。我不這麼認爲,因爲我在apache和uwsgi上使用了相同的包 - 而且應用程序在apache上沒有任何問題。 關於envs中的差異 - 我不這麼認爲,因爲我的舞臺與prod相同 - 它是一面鏡子。 – Lukasz 2012-03-22 17:56:25

+0

@ user1286500您可以在生產服務器上手動導入管理器shell內的sso_token嗎?另外,首先找到並刪除所有的pyc文件。 – okm 2012-03-23 01:49:40

+0

是的,我可以,重新啓動uwsgi後刪除所有pyc – Lukasz 2012-03-23 08:26:56