使用Apache和mod_wsgi在同一服务器上部署Django站点和PHP站点

时间:2013-01-17 15:52:20

标签: django apache mod-wsgi

我目前有一个工作在 cinepass.com.ec 的Django网站,我想在 mobile.cinepass.com.ec 部署另一个PHP网站到同一台服务器

我目前的 httpd.conf (来自DjangoFoo):

<Directory "/home/ec2-user/cinepass/media">
   Order deny,allow
   Allow from all
</Directory>

<Directory "/home/ec2-user/cinepass/cinepass">
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>

Alias /media/ /home/ec2-user/cinepass/media/
ServerAdmin smansfield@palapa.com.ec
ErrorLog "logs/cinepass.com-error_log"
CustomLog "logs/cinepass.com-access_log" common

# mod_wsgi configuration is here
# we are running as user/group 'deamon', if you don't have those you need to change or create.
WSGIDaemonProcess cinepass python-path=/home/ec2-user/cinepass:/home/ec2-user/cinepass/venv/lib/python2.6/site-packages user=daemon group=daemon processes=2 threads=25
WSGIProcessGroup cinepass
# this is our WSGI file.
WSGIScriptAlias / /home/ec2-user/cinepass/cinepass/wsgi.py

我目前的 wsgi.py

import os, sys
sys.path.append('/home/')
sys.path.append('/home/ec2-user/cinepass/')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cinepass.settings_production.py")
os.environ['PYTHON_EGG_CACHE'] = '/tmp'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我如何编辑我的Apache配置,以便我也可以在 mobile.cinepass.com.ec 运行php网站?

1 个答案:

答案 0 :(得分:3)

使用apache´s virtualhosts,这里我在我的服务器中放了一个类似的例子,其中我在主域中有一个djangp应用程序,在子域中有一个joomla。这两个文件都位于/etc/apache2/sites-enabled

Joomla的apache conf文件(名为/etc/apache2/sites-enabled/manual.domain.com):

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin dsanabria@domain.com
    ServerName manual.domain.com

    DocumentRoot "/home/ubuntu/manual/"

    <Directory /home/ubuntu/manual/>
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/manual.domain-error.log

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

    CustomLog /var/log/apache2/manual.domain-access.log combined

</VirtualHost>

django应用程序(名为/etc/apache2/sites-enabled/www.domain.co):

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin diego@diegue.us
    ServerName domain.co
    ServerAlias machete.anotherdomain.com
    Alias /admin/media/ /home/ubuntu/webapps/machete/lib/python2.7/site-packages/grappelli/media/
    Alias /media/ /home/ubuntu/webapps/machete/machete/media/
    Alias /static/ /home/ubuntu/webapps/machete/machete/collected/

    <Directory /home/ubuntu/webapps/machete/lib/python2.7/site-packages/grappelli/media/>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/ubuntu/webapps/machete/lib/python2.7/site-packages/django/contrib/admin/media/ >
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/ubuntu/webapps/machete/machete/media/>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/ubuntu/webapps/machete/machete/collected/>
        Order deny,allow
        Allow from all
    </Directory>

    WSGIScriptReloading On
    WSGIDaemonProcess machete python-path=/home/ubuntu/webapps/machete/lib/python2.7/site-packages
    WSGIProcessGroup machete
    WSGIApplicationGroup machete
    WSGIPassAuthorization On

    WSGIScriptAlias / /home/ubuntu/webapps/machete/machete/machete/wsgi.py
    ErrorLog /var/log/apache2/machete-error.log

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

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

</VirtualHost>

第一个,告诉apache,如果用户访问manual.domain.com,只需使用php应用程序(joomla)进行响应。第二个文件告诉apache,如果用户使用python wsgy(django)通过www.domain.com响应调用服务器。

这是在ubuntu服务器上,redhat / centos / fedora在另一个我记不起的位置找到了启用了网站的文件夹,但无论如何你都可以使用虚拟主机。

通常,我避免弄乱httpd.conf文件,而更喜欢使用虚拟主机。