I have a Django 1.4 application on a Centos 6.2 server (running apache, mysql, php) using mod_wsgi with my project deployed in virtual env. The application itself is the one that I have been using for several years on a hosted service, and now I am deploying it on my own rackspace cloud server. The exact version of the application works fine elsewhere, so this problem is related to the way I deployed it. This is my first python / django deployment - I have installed dozens of LAMP sites before, so I am not familiar with the Django deployments that clearly hold me back.
The application works fine on my server with DEBUG = TRUE
in the settings.py file of the project, but when I change it to FALSE, the front of the site produces [500] Internal server errors.
I know that when setting DEBUG to OFF apache now serves my static files using mod_wsgi (mod_wsgi works fine), which makes me think that “something” in my configuration prevents this. I ran the ./manage.py collectstatic
command, which populated the /static
directory in the /myproject
folder.
I’ve been working on this for several weeks, reading as many deployment guides as I can find, but so far I’m not happy. Your help will be greatly appreciated.
Here are the relevant declarations in the project settings file .py:
settings.py
And here is the wsgi.py file:
The virtual host declaration in httpd.conf looks like this:
############ virtual host declaration in httpd.conf ############## <VirtualHost *:80> ServerName example.org ServerAlias www.example.org DocumentRoot /opt/virtual/myproject Alias /robots.txt /opt/virtual/myproject/static/robots.txt Alias /favicon.ico /opt/virtual/myproject/static/favicon.ico AliasMatch ^/([^/]*\.css) /opt/virtual/myproject/static/styles/$1 Alias /static/ /opt/virtual/myproject/static/ Alias /media/ /opt/virtual/myproject/static/media Alias /images /opt/virtual/myproject/static/images <Directory /opt/virtual/myproject/static> Order deny,allow Allow from all </Directory> <Directory /opt/virtual/myproject/static/media> Order deny,allow Allow from all </Directory> WSGIDaemonProcess example.org python-path=/opt/virtual/myapp/lib/python2.7/site-packages WSGIProcessGroup example.org WSGIScriptAlias / /opt/virtual/myproject/application/wsgi.py <Directory /opt/virtual/myproject> <Files wsgi.py> Order allow,deny Allow from all </Files> </Directory>
My .bashrc file in / ROOT looks like this:
And finally, my error_log showing Traceback:
############### error_log ############### [Mon Jul 09 09:21:13 2012] [error] <WSGIRequest [Mon Jul 09 09:21:13 2012] [error] path:/, [Mon Jul 09 09:21:13 2012] [error] GET:<QueryDict: {}>, [Mon Jul 09 09:21:13 2012] [error] POST:<QueryDict: {}>, [Mon Jul 09 09:21:13 2012] [error] 'DOCUMENT_ROOT': '/opt/virtual/myproject', [Mon Jul 09 09:21:13 2012] [error] 'GATEWAY_INTERFACE': 'CGI/1.1', [Mon Jul 09 09:21:13 2012] [error] 'HTTP_ACCEPT': "*/*", [Mon Jul 09 09:21:13 2012] [error] 'HTTP_HOST': 'example.org', [Mon Jul 09 09:21:13 2012] [error] 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', [Mon Jul 09 09:21:13 2012] [error] 'PATH_INFO': u'/', [Mon Jul 09 09:21:13 2012] [error] 'PATH_TRANSLATED': '/opt/virtual/myproject/application/wsgi.py/', [Mon Jul 09 09:21:13 2012] [error] 'QUERY_STRING': '', [Mon Jul 09 09:21:13 2012] [error] 'REMOTE_ADDR': '99.99.99.99', [Mon Jul 09 09:21:13 2012] [error] 'REMOTE_PORT': '99999', [Mon Jul 09 09:21:13 2012] [error] 'REQUEST_METHOD': 'GET', [Mon Jul 09 09:21:13 2012] [error] 'REQUEST_URI': '/', [Mon Jul 09 09:21:13 2012] [error] 'SCRIPT_FILENAME': '/opt/virtual/myproject/application/wsgi.py', [Mon Jul 09 09:21:13 2012] [error] 'SCRIPT_NAME': u'', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_ADDR': '111.111.111.111', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_ADMIN': ' root@localhost ', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_NAME': 'example.org', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_PORT': '80', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_PROTOCOL': 'HTTP/1.0', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_SIGNATURE': '<address>Apache/2.2.15 (CentOS) Server at example.org Port 80</address>\\n', [Mon Jul 09 09:21:13 2012] [error] 'SERVER_SOFTWARE': 'Apache/2.2.15 (CentOS)', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.application_group': 'example.org|', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.callable_object': 'application', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.handler_script': '', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.input_chunked': '0', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.listener_host': '', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.listener_port': '80', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.process_group': 'example.org', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.request_handler': 'wsgi-script', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.script_reloading': '1', [Mon Jul 09 09:21:13 2012] [error] 'mod_wsgi.version': (3, 3), [Mon Jul 09 09:21:13 2012] [error] 'wsgi.errors': <mod_wsgi.Log object at 0x7f34321aa530>, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f34320e4e40>, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.input': <mod_wsgi.Input object at 0x7f34320e02b0>, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.multiprocess': False, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.multithread': True, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.run_once': False, [Mon Jul 09 09:21:13 2012] [error] 'wsgi.url_scheme': 'http', [Mon Jul 09 09:21:13 2012] [error] 'wsgi.version': (1, 1)}> [Mon Jul 09 09:21:13 2012] [error] ------------------------------------------------------------------------------- [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] mod_wsgi (pid=21520): Exception occurred processing WSGI script '/opt/virtual/myproject/application/wsgi.py'. [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] Traceback (most recent call last): [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__ [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = self.get_response(request) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return callback(request, **param_dict) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = view_func(request, *args, **kwargs) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/views/defaults.py", line 33, in server_error [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return http.HttpResponseServerError(t.render(Context({}))) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 140, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self._render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return compiled_parent._render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] result = block.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] response = view_func(request, *args, **kwargs) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/views/defaults.py", line 33, in server_error [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return http.HttpResponseServerError(t.render(Context({}))) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 140, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self._render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return compiled_parent._render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return self.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] result = block.nodelist.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 823, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] bit = self.render_node(node, context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return node.render(context) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/templatetags/compress.py", line 91, in render [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] rendered_output = compressor.output(self.mode, forced=forced) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/css.py", line 53, in output [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] ret.append(subnode.output(*args, **kwargs)) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/css.py", line 55, in output [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return super(CssCompressor, self).output(*args, **kwargs) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 221, in output [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] finished_content = self.handle_output(mode, filtered_content, forced) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 233, in handle_output [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] return output_func(mode, content, forced) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/compressor/base.py", line 245, in output_file [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] self.storage.save(new_filepath, ContentFile(content)) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/files/storage.py", line 45, in save [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] name = self._save(name, content) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/site-packages/django/core/files/storage.py", line 168, in _save [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] os.makedirs(directory) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] File "/opt/virtual/myapp/lib/python2.7/os.py", line 157, in makedirs [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] mkdir(name, mode) [Mon Jul 09 09:21:13 2012] [error] [client 99.99.99.99] OSError: [Errno 13] Permission denied: '/opt/virtual/myproject/static/CACHE/css'