Programing

apache 및 mod_wsgi를 사용하는 여러 장고 사이트

lottogame 2020. 12. 30. 07:38
반응형

apache 및 mod_wsgi를 사용하는 여러 장고 사이트


내가 데비안 5에서 사용하는 것과 동일한 서버에서 여러 사이트를 호스팅 할, 내가 가지고 있다고 site1, site2그리고 site3, 내 IP는 가정 155.55.55.1:

site1: 155.55.55.1:80  , script at /opt/django/site1/
site2: 155.55.55.1:8080, script at /opt/django/site2/
site3: 155.55.55.1:8090, script at /opt/django/site3/

내 아파치 기본값은 다음과 같습니다.

<VirtualHost *:80>
    ServerName /
    ServerAlias  */
    DocumentRoot /opt/django/site1/
    LogLevel warn
    WSGIScriptAlias / /opt/django/site1/apache/django.wsgi
    Alias /media /opt/django/site1/media/statics
    Alias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media 
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/share/phpmyadmin"
    ServerName /phpmyadmin
    Alias /phpmyadmin /usr/share/phpmyadmin
    <Directory /usr/share/phpmyadmin>
        Options Indexes FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

그리고 여기에 대한 내 WSGI의 설정입니다 site1에서 /opt/django/site1/apache/django.wsgi:

import os, sys
import django.core.handlers.wsgi

sys.path.append('/opt/django')
sys.path.append('/opt/django/site1')

os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
application = django.core.handlers.wsgi.WSGIHandler()

Django 기반 사이트이며 다음과 같이 제공되는 site2및을 어떻게 추가 할 수 있습니까?site3site1


ServerName / ServerAlias ​​지시문이 잘못되었습니다. ServerName은 호스트 이름이어야합니다. ServerAlias를 삭제해야합니다.

그런 다음 파일 시스템에서 포트 번호와 스크립트 위치 만 변경하여 명확하고 중복 된 VirtualHost / Listen 지시문을 수행하십시오.

마지막으로 DocumentRoot를 Django 코드가있는 위치로 설정하지 마십시오. Apache 구성을 채우는 경우 실수로 소스 코드를 다운로드하여 노출하는 것이 더 쉽습니다. 따라서 Django 사이트의 VirtualHost에서 DocumentRoot 지시문을 제거하십시오.

Listen 80

<VirtualHost *:80>
ServerName www.example.com
WSGIScriptAlias / /opt/django/site1/apache/django.wsgi
Alias /media /opt/django/site1/media/statics
Alias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media

<Directory opt/django/site1/apache>
Order allow,deny
Allow from all
</Directory>

<Directory /home/myuser/Django-1.1/django/contrib/admin/media>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Listen 8080

<VirtualHost *:8080>
ServerName www.example.com
WSGIScriptAlias / /opt/django/site2/apache/django.wsgi
Alias /media /opt/django/site2/media/statics
Alias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media

<Directory opt/django/site2/apache>
Order allow,deny
Allow from all
</Directory>

<Directory /home/myuser/Django-1.1/django/contrib/admin/media>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Listen 8090

<VirtualHost *:8090>
ServerName www.example.com
WSGIScriptAlias / /opt/django/site3/apache/django.wsgi
Alias /media /opt/django/site3/media/statics
Alias /admin_media  /home/myuser/Django-1.1/django/contrib/admin/media

<Directory opt/django/site3/apache>
Order allow,deny
Allow from all
</Directory>

<Directory /home/myuser/Django-1.1/django/contrib/admin/media>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

정적 파일에 대한 액세스를 허용하기 위해 누락 된 Directory 지시문도 추가했습니다. 그러나 경로를 검토해야합니다.

반드시 읽어보십시오 :

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files

자세한 내용은.


업데이트 1

BTW, since you are using PHP in same Apache, you would be much better off using mod_wsgi daemon mode and push each Django instance out into its own separate process. That allows those processes to be multithreaded, even though main Apache processes are forced to be single threaded because of PHP. End result will be much much less memory being used than if running multiple Django instances in each process under embedded mode with prefork MPM. Your Django code just needs to be thread safe. Configuration in addition to above would be to add WSGIDaemonProcess/WSGIProcessGroup to each Django VirtualHost, where name of daemon process group is different for each VirtualHost.

<VirtualHost *:80>
WSGIDaemonProcess site1 display-name=%{GROUP}
WSGIProcessGroup site1
... existing stuff
</VirtualHost>

<VirtualHost *:8080>
WSGIDaemonProcess site2 display-name=%{GROUP}
WSGIProcessGroup site2
... existing stuff
</VirtualHost>

<VirtualHost *:8090>
WSGIDaemonProcess site3 display-name=%{GROUP}
WSGIProcessGroup site3
... existing stuff
</VirtualHost>

This also allows you to more easily restart each Django instance without restart whole of Apache. Read:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Process http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode


Putting all virtualHost configuration in one place works fine, but Debian has its own concept by separating them in a file for each site in /etc/apache2/sites-available, which are activated by symlinking them in ../sites-enabled. In this way a server-admin could also assign separate access rights to the config file for each of the site-admin unix users, scripts can check if a site is active etc.

Basically it would be nice to have one central howto for Django-Admin installations, the current multitude of separate docs, links and blog articles is not really helpful for the proliferation of Django.

ReferenceURL : https://stackoverflow.com/questions/1553165/multiple-django-sites-with-apache-mod-wsgi

반응형