Setting up multiple Django applications on the same server

I tried to configure two separate Django applications on the same server so that they could be accessed using different URLs ... using the configuration below, I can access the first application, but I don’t understand how to enable the setting for the second application . Also, admin media resources do not load

NameVirtualHost *:8032

  ServerName localhost ServerAdmin webmaster@example.com

 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"

+3
source share
5 answers

/etc/apache 2/sites-available. (, example1.com, example12.com ..). a2ensite, Apache.

:

<Virtualhost *:8032>
ServerName localhost 
ServerAdmin webmaster@example.com
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>

. apache , , -, Lighttpd Nginx, apache django. NginX

mod_wsgi, , . , .

+2

, , VirtualHost . VirtualHost, , VirtualHost. mod_python, mod_wsgi. Alias ​​ , , , URL, , , .

, , AddHandler .wsgi, , .wsgi URL . , .wsgi URL.

, :

  • , VirtualHost.

  • , URL- VirtualHost .

  • , -URL .

  • , - . .

+2

Apache :

<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:

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

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

<locationmatch ".(jpg|gif|png)$">
    SetHandler None
</locationmatch>
+1

, , .

0
source

Source: https://habr.com/ru/post/1712786/


All Articles