tags:

views:

424

answers:

5

Hi all...I've been trying to configure two separate Django apps on one server such that they can be accessed at different URL's...using the below config, I can access the first app, but I'm at a loss at how to include the setup for the second app. The admin media is also not being loaded at all

NameVirtualHost *:8032

ServerName localhost ServerAdmin [email protected]

 DocumentRoot "/usr/local/www/djcode/test"
 <Directory "/usr/local/www/djcode/test">
     Options +ExecCGI
     Order allow,deny
     Allow from all
 </Directory>
 Alias /site_media "/usr/local/www/djcode/test/site_media/"

 Alias /media "/usr/local/www/djcode/test/site_media/media/"
 WSGIDaemonProcess test user=www group=www processes=2 threads=5
 WSGIProcessGroup test
 AddHandler wsgi-script .wsgi
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /test.wsgi/$1 [QSA,L]

ServerName localhost ServerAlias localhost DocumentRoot "/usr/local/www/apache22/data"

+1  A: 

You can create multiple Virtual Hosts in Apache, and modify the following for each app:

<VirtualHost *:80>
  DocumentRoot /var/www
  ServerName www.site.com

      <location "/<name>">
           SetHandler python-program
           PythonHandler django.core.handlers.modpython
           SetEnv DJANGO_SETTINGS_MODULE <app name>.settings
           PythonPath "['/path/to/app'] + sys.path"
       </location>
 </VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/site2
  ServerName www.site2.com

      <location "/<name2>">
           SetHandler python-program
           PythonHandler django.core.handlers.modpython
           SetEnv DJANGO_SETTINGS_MODULE <app2 name>.settings
           PythonPath "['/path/to/app2'] + sys.path"
       </location>
 </VirtualHost>

edit: also add the following to each Virtual Host

<location "/media">
    SetHandler None
</location>

<location "/admin_media">
    SetHandler None
</location>

<locationmatch ".(jpg|gif|png)$">
    SetHandler None
</locationmatch>
Jason
thnx...I'll try this...how about for the admin media...will this work?
This configuration is for mod_python, they were using mod_wsgi.
Graham Dumpleton
A: 

For the admin media you can put the same alias in both virtual hosts, or if they need to be different setup a copy of them and have 2 different aliases.

Justin Hamade
+1  A: 

I've encountered something like this. Here's some related questions, albeit not precisely on point:

Hope it helps, though.

Brian M. Hunt
+1  A: 

Make two configuration files in /etc/apache2/sites-available folder. Give them proper logical names according to your sites (e.g. example1.com , example12.com etc). Use a2ensite command to enable both of them and restart your apache server.

Each of your config file should look something like this:

<Virtualhost *:8032>
ServerName localhost 
ServerAdmin [email protected]
DocumentRoot "/usr/local/www/djcode/test"
 <Directory "/usr/local/www/djcode/test">
     Options +ExecCGI
     Order allow,deny
     Allow from all
 </Directory>
 Alias /site_media "/usr/local/www/djcode/test/site_media/"

 Alias /media "/usr/local/www/djcode/test/site_media/media/"
 WSGIDaemonProcess test user=www group=www processes=2 threads=5
 WSGIProcessGroup test
 AddHandler wsgi-script .wsgi
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /test.wsgi/$1 [QSA,L]
 </Virtualhost *:8032>

You'll also need to add up some directives to serve static content. Serving static content from apache has overhead so it'll be a better idea if you server it using some lightweight webserver such as Lighttpd or Nginx and connect to apache using reverse proxy to serve the django based content. Here's a tutorial on using NginX

Since you are using mod_wsgi, you can run each site as different user as well so that two of them may not access each other's data. This is useful if the two sites belong to different stakeholders.

sharjeel
A: 

It is not clear whether you want them to both be hosted under the same VirtualHost or not. Others have gone off and told you to use separate VirtualHost's but that isn't necessary and it can be done under the same VirtualHost. Some have provided a configuration using mod_python when you were actually using mod_wsgi. You also technically didn't need the Alias directives for the static media, although where you stored them may need to change depending on URL you expected to be able to use to access them.

That all said, for your current configuration, because you have used AddHandler to map .wsgi files you can already host multiple applications, you would just need to create multiple .wsgi files in the document directory and use the appropriate URL to access them. Further configuration could be added to avoid needing to specify the '.wsgi' extensions in the URL.

I can give a proper answer if you do the following:

  • Say whether they need to be under the same VirtualHost.

  • Say what URL within the VirtualHost each distinct application should be accessible as.

  • Say what media URL should be used for each distinct application.

  • Say whether each should run in a separate process, or whether them running in different sub interpreters of the same process is adequate. Running in separate processes would allow each to be restarted independently when making code changes.

Graham Dumpleton