这是我的项目结构
prod/
projectName/
test/
projectName/
我的apache设置已配置为: www.projectname.com指向:
prod/projectName/
和test.projectname.com指向:
test/projectName/
这会在django中运作吗?
以下是两个网址的虚拟主机配置
测试:
<VirtualHost *:80>
ServerAdmin webmaster@projectname.com
ServerName test.projectname.com
ServerAlias test.projectname.com
DocumentRoot /django_projects/test/projectname/
ErrorLog /django_projects/test/projectname/logs/error.log
CustomLog /django_projects/test/projectname/logs/access.log combined
WSGIScriptAlias / /django_projects/test/projectname/projectname/wsgi.py
Alias /static /django_projects/test/projectname/static/
Alias /media /django_projects/test/projectname/media/
<Directory /django_projects/test/projectname>
Order allow,deny
Allow from all
</Directory>
<Directory /django_projects/test/projectname/templates>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
WSGIPythonPath /django_projects/test/projectname/
PROD:
<VirtualHost *:80>
ServerAdmin webmaster@projectname.com
ServerName projectname.com
ServerAlias projectname.com
DocumentRoot /django_projects/prod/projectname/
ErrorLog /django_projects/prod/projectname/logs/error.log
CustomLog /django_projects/prod/projectname/logs/access.log combined
WSGIScriptAlias / /django_projects/prod/projectname/projectname/wsgi.py
Alias /static /django_projects/prod/projectname/static/
Alias /media /django_projects/prod/projectname/media/
<Directory /django_projects/prod/projectname>
Order allow,deny
Allow from all
</Directory>
<Directory /django_projects/prod/projectname/templates>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
WSGIPythonPath /django_projects/prod/projectname/
因为现在test.projectname.com和www.projectname.com都指向prod / projectName /尽管有不同的vhost配置。
谢谢!
答案 0 :(得分:0)
以下是如何做到这一点。作为守护进程运行。还要确保正确配置了wsgi.py脚本。
配置测试,然后为prod配置相同。但是它们将被配置为apache中的不同站点:
在/etc/apache2/sites-available/test.projectname.com.conf
中<VirtualHost *:80>
ServerAdmin webmaster@projectname.com
ServerName test.projectname.com
ServerAlias test.projectname.com
DocumentRoot /django_projects/test/projectname/
ErrorLog /django_projects/test/projectname/logs/error.log
CustomLog /django_projects/test/projectname/logs/access.log combined
WSGIDaemonProcess test processes=2 threads=15
WSGIScriptAlias / /django_projects/test/projectname/projectname/wsgi.py
Alias /static /django_projects/test/projectname/static/
Alias /media /django_projects/test/projectname/media/
<Directory /django_projects/test/projectname>
WSGIProcessGroup test
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
<Directory /django_projects/test/projectname/templates>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
在/etc/apache2/sites-available/projectname.com.conf
中<VirtualHost *:80>
ServerAdmin webmaster@projectname.com
ServerName projectname.com
ServerAlias projectname.com
DocumentRoot /django_projects/prod/projectname/
ErrorLog /django_projects/prod/projectname/logs/error.log
CustomLog /django_projects/prod/projectname/logs/access.log combined
WSGIDaemonProcess prod processes=2 threads=15
WSGIScriptAlias / /django_projects/prod/projectname/projectname/wsgi.py
Alias /static /django_projects/prod/projectname/static/
Alias /media /django_projects/prod/projectname/media/
<Directory /django_projects/prod/projectname>
WSGIProcessGroup prod
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
<Directory /django_projects/prod/projectname/templates>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
完成后:
$ sudo a2ensite test.projectname.com
$ sudo a2ensite projectname.com
类似的东西:)