多个Django项目,相同的域名,相同的服务器apache

时间:2014-12-03 06:31:06

标签: django apache2 mod-wsgi apache-config

我有一个Django项目已经托管在域名上,例如example.com。它的主页是

  

example.com/demotool/

现在我开发了另一个Django项目,希望在相同的apache服务器上托管相同的域名,并设置不同的URL。

例如,其根URL将是

  

example.com/demotool/client1 /

我为两个项目都有单独的project_name.wsgi文件。

目录结构就像

/home/user/public_html/example.com/project/project_name.wsgi
/home/user/public_html/example.com/project1/project1_name.wsgi

wsgi文件的内容是

> import os import sys
> sys.path.append('/home/user/public_html/example.com/project/')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' 
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()

/etc/apache2/sites-available/example.com的内容是

> <VirtualHost *:80>
>         ServerName example.com
>         ServerAlias www.example.com
>         WSGIScriptAlias / /home/user/public_html/example.com/project/project_name.wsgi
>         Alias /static/ /home/user/public_html/example.com/project/static/
>         <Location "/static/">
>             Options -Indexes
>         </Location>
> </VirtualHost>

现在我应该在apache配置文件中添加或修改什么,以在同一域名和同一服务器中添加另一个项目。 这个问题有重复,但我不知道如何让它工作,请帮助。 提前致谢

2 个答案:

答案 0 :(得分:0)

试试这个 - :

<virtualhost *:80>
ServerName example.com
WSGIScriptAlias /site1 /home/user/public_html/example.com/project/project_name.wsgi
WSGIScriptAlias /site2 /home/user/public_html/example.com/project1/project1_name.wsgi

<Directory /home/user/public_html/example.com/project>
Order allow,deny
Allow from all
</Directory>

<Directory /home/user/public_html/example.com/project1>
Order allow,deny
Allow from all
</Directory>
</virtualhost>

如果某些内容仍然无效,请进行评论。欢呼: - )

答案 1 :(得分:0)

我总是这样做:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com

    WSGIDaemonProcess project1-http python-home=/home/deployer/.virtualenvs/project1
    WSGIScriptAlias /project1 /var/www/html/project1/project1/wsgi.py process-group=project1-http application-group=project1-http
    WSGIProcessGroup project1-http
    Alias /project1/static/ /var/www/html/project1/static/

    WSGIDaemonProcess project2-http python-home=/home/deployer/.virtualenvs/project2
    WSGIScriptAlias /project2 /var/www/html/project2/project2/wsgi.py process-group=project2-http application-group=project2-http
    WSGIProcessGroup project2-http
    Alias /project2/static/ /var/www/html/project2/static/
</VirtualHost>

我希望这有帮助!