четвер, 2 грудня 2010 р.

Configure wsgi for Django on Apache

I was need to run old and new version of my site.
So how to configure 2 version of your project on one apache server?
I've used 2 ports: 80(default) and 8080.
Edit your /etc/apache2/ports.conf and add this lines
NameVirtualHost *:80
Listen 80
NameVirtualHost *:8080
Listen 8080

Then go to /etc/apache2/sites-enabled/ , edit @000-default(default) and add those lines:

<VirtualHost *:80>
ServerAdmin webmaster@{{your_domain}}
DocumentRoot /var/www/

WSGIScriptAlias / /{__path_to_dir_where_your_project_is__}/django.wsgi
WSGIDaemonProcess {name_of_process} user={user_name} group={group_name} processes=5 threads=1
WSGIProcessGroup {name_of_process}

<Directory "{__path_to_dir_where_your_project_is__}">
Order allow,deny
Allow from all
</Directory>

<Location "site_media">
SetHandler None
</Location>

Alias /site_media/ /{__path_to_dir_where_your_project_is__}/{__path_to_media_folder__}/
<Directory "{__path_to_dir_where_your_project_is__}/{__path_to_media_folder__}">
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all

ExpiresActive On
ExpiresDefault "access plus 5 days"
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

</VirtualHost>

<VirtualHost *:8080>
ServerAdmin webmaster@{{your_domain}}
DocumentRoot /var/www/
ServerName {{your_domain}}
WSGIScriptAlias / /{__path_to_dir_where_project_is(another_version)__}/django.wsgi
WSGIDaemonProcess {name_of_process} user={user_name} group={group_name} processes=5 threads=1
WSGIProcessGroup {name_of_process}

<Directory "{__path_to_dir_where_your_project_is(another_version)__}">
Order allow,deny
Allow from all
</Directory>

<Location "site_media">
SetHandler None
</Location>

Alias /site_media/ /{__path_to_dir_where_your_project_is(another_version)__}/{__path_to_media_folder__}/
<Directory "{__path_to_dir_where_your_project_is(another_version)__}/{__path_to_media_folder__}">
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all

ExpiresActive On
ExpiresDefault "access plus 5 days"
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
<VirtualHost>

and finaly create file django.wsgi in {__path_to_dir_where_your_project_is__} and {__path_to_dir_where_your_project_is(another_version)__}
Here it is:
#!/usr/bin/python
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = '{settings_file_of_your_project}'
sys.path.append('{__path_to_your_project__}')
sys.path.append('{__path_to_dir_where_your_project_is__}')

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Now you can start(restart) you apache.
Thats all folks!
p.s. it's work on my machine)

Немає коментарів:

Дописати коментар