Environment variables Django with Apache on Ubuntu
wsgi.py of your django project
"""
WSGI config for Yourproject project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Yourproject.settings")
from django.core.wsgi import get_wsgi_application
#application = get_wsgi_application()
_application = get_wsgi_application()
env_variables_to_pass = ['first_envvar', 'second_envvar', ]
def application(environ, start_response):
# pass the WSGI environment variables on through to os.environ
for var in env_variables_to_pass:
os.environ[var] = environ.get(var, '')
return _application(environ, start_response)
your apache conf file in /etc/apache2/sites-available/yourwebsite.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
SetEnv first_envvar envvarval1
SetEnv secong_envvar envvarval2
......(the rest of the files)Resources:
- http://ericplumb.com/blog/passing-apache-environment-variables-to-django-via-mod_wsgi.html
Comments
Post a Comment