多个Django项目apache虚拟主机
我是apache的新手。 所以我尝试在一台Ubuntu服务器上用一个IP地址运行至少两个不同的django项目多个Django项目apache虚拟主机,django,apache,mod-wsgi,Django,Apache,Mod Wsgi,我是apache的新手。 所以我尝试在一台Ubuntu服务器上用一个IP地址运行至少两个不同的django项目 IP:123.456.789 域1:www.example.de for Project1 域2: www.test.de for Proejct2 两个域的DNS都指向同一IP地址。 我在守护程序模式下使用apache2和mod_wsgi。 每个项目在~/中都有自己的目录。 我还在项目目录中安装了一个带有python的virtaulenv 问题是,无论我如何配置apache2.c
- IP:123.456.789
- 域1:www.example.de for Project1
- 域2: www.test.de for Proejct2
Listen 80
<VirtualHost *:80>
ServerName www.example.de
WSGIScriptAlias / /home/user/example/example-project/wsgi.py
Alias /static/ /home/user/example/static/
WSGIPythonPath /home/user/example
<Directory /home/user/example/static>
Require all granted
</Directory>
<Directory /home/user/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess example.de python-path=/home/user/example:/home/user/example/exampleenv/lib/python2.7/site-packages
WSGIProcessGroup example.de
</VirtualHost>
Listen 8080
<VirtualHost *:80>
Servername www.test.de
WSGIScriptAlias / /home/user/test/test-project/wsgi.py
Alias /static/ /home/user/test/static/
<Directory /home/user/test/static>
Require all granted
</Directory>
<Directory /home/user/test/test-project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess test.de python-path=/home/user/test:/home/user/test/testenv/lib/python2.7/site-packages
WSGIProcessGroup test.de
</VirtualHost>
听80
服务器名www.example.de
WSGIScriptAlias//home/user/example/example project/wsgi.py
别名/static//home/user/example/static/
WSGIPythonPath/home/user/example
要求所有授权
要求所有授权
WSGIDaemonProcess example.de python path=/home/user/example:/home/user/example/exampleenv/lib/python2.7/site-packages
WSGIProcessGroup example.de
听8080
服务器名www.test.de
WSGIScriptAlias//home/user/test/test project/wsgi.py
别名/静态//主页/用户/测试/静态/
要求所有授权
要求所有授权
WSGIDaemonProcess test.de python path=/home/user/test:/home/user/test/testenv/lib/python2.7/site-packages
WSGIProcessGroup test.de
即使我的配置有问题,为什么在我评论这个博客的所有内容时它仍然运行?apache还从哪里获得信息?
<VirtualHost *:80>
ServerName www.example1.com
ServerAlias example1.com
ServerAdmin admin@example1.com
DocumentRoot "/var/www/example1"
WSGIScriptAlias / /var/www/example1/example1/wsgi.py
WSGIDaemonProcess www.example1.com python-path=/var/www/example1:/usr/local/lib/python2.7/site-packages
<Location />
WSGIProcessGroup www.example1.com
</Location>
<Directory /var/www/example1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog /var/www/logs/example1.log
</VirtualHost>
<VirtualHost *:80>
ServerName www.example2.com
ServerAlias exolcorporation.com
ServerAdmin admin@example2.com
DocumentRoot "/var/www/example2"
WSGIScriptAlias / /var/www/example2/example2/wsgi.py
WSGIDaemonProcess www.example2.com python-path=/var/www/example2:/usr/local/lib/python2.7/site-packages
<Location />
WSGIProcessGroup www.example2.com
</Location>
<Directory /var/www/example2>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog /var/www/logs/example2.log
</VirtualHost>
服务器名www.example1.com
ServerAlias example1.com
服务器管理员admin@example1.com
DocumentRoot“/var/www/example1”
WSGIScriptAlias//var/www/example1/example1/wsgi.py
WSGIDaemonProcess www.example1.com python路径=/var/www/example1:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup www.example1.com
要求所有授权
ErrorLog/var/www/logs/example1.log
服务器名www.example2.com
ServerAlias exolcorporation.com
服务器管理员admin@example2.com
DocumentRoot“/var/www/example2”
WSGIScriptAlias//var/www/example2/example2/wsgi.py
WSGIDaemonProcess www.example2.com python路径=/var/www/example2:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup www.example2.com
要求所有授权
ErrorLog/var/www/logs/example2.log
尝试替换路径和域名
在WSGIDaemonProcess中,使用virtualenv的路径
在本例中,我没有使用virtualenv
这段代码对我来说在aws ubuntu上很好为什么你的请求最终会被错误的Django实例处理的主题已经在以下博客文章中详细记录:
我建议在第二个虚拟主机上添加一个语法错误(“xxx”本身在一行上),并查看Apache在尝试启动时是否输出错误。这将确认是否正在读取文件。明天将签出,知道apache为什么运行我的项目吗,即使我已经删除了apache.conf中的所有相关行?是的,我在第二个虚拟主机中遇到语法错误。这真的很奇怪,即使当我注释第一个虚拟主机的所有行时,所有域都将我指向第一个VH。在所有
VirtualHost
定义之外的全局范围添加,WSGIRestrictEmbedded
。这将确保mod_wsgi只在守护进程中运行,而任何东西都不能在嵌入式模式下运行。可能不会更改任何内容,但希望检查是否以某种方式找到某个定义,使其在嵌入式模式下运行。如果在添加后失败,那么知道这一点可能很有用。顺便说一句,它们是您的真实主机名,还是您更改了配置以保护真实的主机名?好的,我现在意识到它一切正常。这两个项目基本上是一样的,我只是在Project2中更改了a-tag,我想我会看到不同之处。我没有,我想是因为该站点缓存在serversite的某个地方。现在我只需要弄清楚在哪里…读取磁盘的更改代码并不意味着事情会自动反映在所提供的服务中。但在您的情况下,在缓存页面上的生存时间听起来要长一点。