帮助在单个子域下设置多个 django 站点

发布于 2024-11-25 14:23:42 字数 458 浏览 1 评论 0原文

在同一个子域下,我需要设置几个独立的站点,每个站点都运行django,这些站点是完全独立的。每个站点都应该位于其自己的子目录中,并且这些子目录必须受密码保护。

例如: <代码>

subdomain.example.com/site1
subdomain.example.com/site2
I am using apache2 and have a virtual server entry for the subdomain. django is run using FastCGI.

基本上,我不知道如何设置。我应该在我的中放入什么?子域的条目?通常,对于子域下的单个 django 站点,我会将 WSGIScriptAlias 指向应执行的 python 脚本,但是对于多个站点我该怎么办? 请帮忙 谢谢 康斯坦丁

Under the same subdomain, I need to set up several independent sites each running django, these sites are totally separate. Each site should be in its own subdirectory, and these subdirectories have to be password-protected.

for example:

subdomain.example.com/site1
subdomain.example.com/site2


I am using apache2 and have a virtual server entry for the subdomain. django is run using FastCGI.

basically, I do not know how to set this up. What do I put in to my <VirtualHost> entry for the subdomain? Usually, for a single django site under a subdomain I would put WSGIScriptAlias pointing to the python script that should be executed, but what do i do for multiple sites?
please help
thanks
konstantin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-12-02 14:23:42

这些不是单独的虚拟主机。

它们是虚拟主机内单独的“位置”(或“目录”)。

您将执行类似于以下操作的操作。

  ServerName example.com
  DocumentRoot /opt/app/site1/public_html
  Alias /media/site1 /opt/app/site1/media
  DocumentRoot /opt/app/site2/public_html
  Alias /media/site2 /opt/app/site2/media

  RewriteEngine On
  RewriteRule ^/(media/site1.*)$ /$1 [QSA,L,PT]
  RewriteRule ^/(media/site2.*)$ /$1 [QSA,L,PT]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^/site1(.*)$ /mysite1.fcgi/$1 [QSA,L]
  RewriteRule ^/site1(.*)$ /mysite2.fcgi/$1 [QSA,L]

[这未经测试,因为我们为此使用 mod_wsgi。]

These aren't separate virtual hosts.

They are separate "locations" (or "directories") within a virtual host.

You'll do something a bit like the following.

  ServerName example.com
  DocumentRoot /opt/app/site1/public_html
  Alias /media/site1 /opt/app/site1/media
  DocumentRoot /opt/app/site2/public_html
  Alias /media/site2 /opt/app/site2/media

  RewriteEngine On
  RewriteRule ^/(media/site1.*)$ /$1 [QSA,L,PT]
  RewriteRule ^/(media/site2.*)$ /$1 [QSA,L,PT]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^/site1(.*)$ /mysite1.fcgi/$1 [QSA,L]
  RewriteRule ^/site1(.*)$ /mysite2.fcgi/$1 [QSA,L]

[This is untested, since we use mod_wsgi for this.]

很酷不放纵 2024-12-02 14:23:42

这是我的配置:
<代码>

<VirtualHost *:12665>
    ServerName subdomain.example.com
    DocumentRoot /path
    WSGIScriptAliasMatch ^/([^/]+) /sites/$1/httpd/django.wsgi
    <DirectoryMatch ^/sites/[^/]+/httpd>
        Order deny,allow
        Allow from all
    </DirectoryMatch>
</VirtualHost>

here is my configuration:

<VirtualHost *:12665>
    ServerName subdomain.example.com
    DocumentRoot /path
    WSGIScriptAliasMatch ^/([^/]+) /sites/$1/httpd/django.wsgi
    <DirectoryMatch ^/sites/[^/]+/httpd>
        Order deny,allow
        Allow from all
    </DirectoryMatch>
</VirtualHost>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文