所以我将从解释我的目标开始。我有多个域,我将它们路由到服务器上的一个简单 IP 地址。我希望 Apache 将每个域路由到wsgi.py
其 Django 项目中的适当文件。似乎官方文档是为每台服务器处理一个域而编写的。如果您想查看他们的文档,他们就在这里。我还想指出,我真的不想使用 Django 站点框架,因为它似乎不适合我的需要。
所以我会告诉你我一直在尝试什么。我把它放在sites-available/000-default.conf
文件中。
<VirtualHost *:80>
ServerName www.foo.com
ServerAlias foo.com
Alias /media/ /path/to/foo.com/media/
Alias /static/ /path/to/foo.com/static/
<Directory /path/to/foo.com/static>
Require all granted
</Directory>
<Directory /path/to/foo.com/media>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/foo.com/foo/wsgi.py
<Directory /path/to/foo.com/foo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.foo2.com
ServerAlias foo2.com
Alias /media/ /path/to/foo2.com/media/
Alias /static/ /path/to/foo2.com/static/
<Directory /path/to/foo2.com/static>
Require all granted
</Directory>
<Directory /path/to/foo2.com/media>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/foo2.com/foo2/wsgi.py
<Directory /path/to/foo2.com/foo2>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
奇怪的是,两个网站都没有加载。我刚得到一个 Apache 只是为我的空文件索引页面提供服务。请注意,我没有WSGIPythonPath /path/to/foo2.com/
包括在内。包含它时出现错误。而且我不完全确定它需要。
我也做了。
- 在
apache2.conf
文件中设置一个 ServerName。 - 修改
wsgi.py
文件以处理多个站点。 - 我还尝试在
/etc/hosts
文件中设置我的 IP。
所以这主要是全部。我在整个互联网上进行了搜索,但找不到任何最新的解决方案。如果您知道解决此问题的方法,请告诉我。如果可能,请尝试在您的答案中包含代码。
PS。我正在使用 python 2.7 在 Ubuntu Server 14.04 中运行它。