如何使用 Django 设置域别名?

发布于 2024-07-16 08:15:52 字数 123 浏览 5 评论 0原文

我正在用 Django 创建一个网站,它由两部分组成:网站本身和论坛。 它们都位于不同的域中,即 example.com 和 exampleforum.com。 当论坛和主站点属于同一实例时,如何在 Django 中完成此操作?

I am working on creating a website in Django which consists of two parts: the website itself, and the forum. They will both be on separate domains, i.e. example.com and exampleforum.com. How can this be done in Django, when the forum and main site are part of the same instance?

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

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

发布评论

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

评论(1

时光礼记 2024-07-23 08:15:52

这是在 Web 服务器级别完成的。 Django 不关心传入请求的域。

如果您使用 Apache,只需将多个 ServerAlias 指令放入虚拟主机中,如下所示:

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    ServerAlias forum.mydomain.com
    ... other directives as needed ...
</VirtualHost>

这告诉 Apache 将所有这些域的请求定向到同一个实例。

对于 nginx,您的配置文件将类似于:

server {
    listen 80;
    server_name   www.mydomain.com   mydomain.com   forum.mydomain.com;
    ... other directives as needed ...
}

This is done at the web server level. Django doesn't care about the domain on the incoming request.

If you are using Apache just put multiple ServerAlias directives inside your virtual host like this:

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    ServerAlias forum.mydomain.com
    ... other directives as needed ...
</VirtualHost>

This tells Apache to direct requests for all of those domains into the same instance.

For nginx your config file would look something like:

server {
    listen 80;
    server_name   www.mydomain.com   mydomain.com   forum.mydomain.com;
    ... other directives as needed ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文