使用 apache 在同一台 Linux 机器上运行 django 站点和 wiki
我在强制基于 django 的网站和“常规”网站(即 wiki)在同一台机器上工作时遇到了一些问题,最重要的是,我对这个东西有点陌生......
我一直在尝试使用 VirtualHost 进行设置,但似乎效果不太好。换句话说,我可以同时运行 django 站点(已经以 host.com/djangosite 的形式)和其他站点(即 host.com/othersite1) 。一次只有一个工作,看起来 apache 运行它找到的第一个 VirtualHost。
服务器中的结构看起来像这样
/var/www/djangosite
/var/www/othersite1
/var/www/othersite2 ... etc
现在启用了站点,我进行了一些实验,最终最终得到了一个包含两个虚拟主机的文件:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/djangosite
ServerName host.com/djangosite
Alias /m/ "/var/www/djangosite/forum/skins/"
<Directory "/var/www/djangosite/forum/skins">
Order allow,deny
Allow from all
</Directory>
Alias /upfiles/ "/var/www/djangosite/forum/upfiles/"
<Directory "/var/www/djangosite/forum/upfiles">
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /djangosite /var/www/djangosite/djangosite.wsgi
CustomLog /var/log/djangosite.access.log common
ErrorLog /var/log/djangosite.error.log
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/othersite1
ServerName host.com/othersite1
</VirtualHost>
两个虚拟主机本身都可以,即当我将其放入站点中的文件中时 -启用 djangosite 工作正常,但未找到第二个(文档根目录植根于文件系统结构中错误的目录)。如果我把第二个虚拟主机放在上面,它就可以工作,但 djangosite 就不行。
好的。所以现在一个真正的问题是,有一个方法可以在一个 linux/apache 配置上使用一个 NIC 和一个主机名运行 djangosite 和“常规”站点。
感谢您至少阅读:)
I've got a bit of a problem with forcing django based site and a "regular" sites i.e. wikis to work on the same machine, and to top it I'm kinda new to this stuff...
I've been trying to setup this using the VirtualHost but it seems that this does not work very well. In other words I can either run the django site (alredy in form of host.com/djangosite) and other sites in the same time (i.e host.com/othersite1). Only one works at a time it looks like the apache runs first VirtualHost it finds.
the structure in the server looks like this
/var/www/djangosite
/var/www/othersite1
/var/www/othersite2 ... etc
Now the sites-enabled, I experimented a bit and finally ended up in one file with two VirtualHosts for now:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/djangosite
ServerName host.com/djangosite
Alias /m/ "/var/www/djangosite/forum/skins/"
<Directory "/var/www/djangosite/forum/skins">
Order allow,deny
Allow from all
</Directory>
Alias /upfiles/ "/var/www/djangosite/forum/upfiles/"
<Directory "/var/www/djangosite/forum/upfiles">
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /djangosite /var/www/djangosite/djangosite.wsgi
CustomLog /var/log/djangosite.access.log common
ErrorLog /var/log/djangosite.error.log
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/othersite1
ServerName host.com/othersite1
</VirtualHost>
On their own both VirtualHosts do ok, i.e. when I put this in a file in sites-enabled the djangosite works fine, the second is not found, (something with document root being rooted at wrong dir in filesystem structure). If I put the second Vhost on top it works the djangosite doesn't.
Ok. so now a real question is there a recipe for running djangosite and "regular" site on one linux/apache configuration with one NIC and one hostname.
thanks for at least reading :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要两个单独的虚拟主机。只需将它们放在同一个服务器中,服务器名称为“host.com”即可。然后您可以使用别名 - Django 站点的 WSGIScriptAlias 和 wiki 的普通别名。
请注意:请不要将您的 Django 代码放在 DocumentRoot 中。这是危险的 - 它使人们有可能看到您的代码,包括 settings.py 中的密码等。将其移至其他位置,并省略 DocumentRoot 指令。
You don't need two seperate VirtualHosts. Just put them both in the same one, with the ServerName as just "host.com". Then you can use aliases - the WSGIScriptAlias for the Django site, and a normal Alias for the wiki.
One note: please do not put your Django code in the DocumentRoot. This is dangerous - it makes it potentially possible for people to see your code, including your passwords etc in settings.py. Move it somewhere else, and leave out the DocumentRoot directive.