如何使用 Django 设置域别名?
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在 Web 服务器级别完成的。 Django 不关心传入请求的域。
如果您使用 Apache,只需将多个 ServerAlias 指令放入虚拟主机中,如下所示:
这告诉 Apache 将所有这些域的请求定向到同一个实例。
对于 nginx,您的配置文件将类似于:
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:
This tells Apache to direct requests for all of those domains into the same instance.
For nginx your config file would look something like: