允许的主机在EC2上的设置的Django [英] Allowed Host Setting for Django on EC2

查看:135
本文介绍了允许的主机在EC2上的设置的Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚部署到Amazon EC2的汇出djnago堆栈和我在同ALLOWED_HOSTS在settings.py文件中设置的麻烦。我不知道使用或在哪里可以找到它什么主机名。我曾尝试内部IP,外部IP,本地主机,域名。这得到了500错误页面,停止的唯一的事情,就是:

I just deployed to an Amazon EC2 bitnami djnago stack and I'm having trouble with the ALLOWED_HOSTS setting in the settings.py file. I am not sure what hostname to use or where to find it. I have tried internal IP, external IP, localhost, domain name. The only thing that gets the 500 error pages to stop, is:

ALLOWED_HOSTS = ['*']

不过,这是一个安全问题。我在想什么?

But, this is a security issue. What am I missing?

推荐答案

将其设置为 -

ALLOWED_HOSTS = [
  '.yourdomain.com'
]

其中, yourdomain.com 是您用来访问它的站点名称。

Where yourdomain.com is the domain name you're using to access it.

借助文档说 -

在此列表中的值可以是完全限定的名称(如:   'www.example.com),在这种情况下,他们将被匹配对   请求的主机头完全相同(不区分大小写,不包括端口)。   值与期初可以作为一个子域通配符:   '.example.com的'将匹配example.com,www.example.com,和任何其他   子域example.com的。

Values in this list can be fully qualified names (e.g. 'www.example.com'), in which case they will be matched against the request’s Host header exactly (case-insensitive, not including port). A value beginning with a period can be used as a subdomain wildcard: '.example.com' will match example.com, www.example.com, and any other subdomain of example.com.

当你将它设置为 www.yourdomain.com ,一定有一些要求,另一个子域,比 WWW 。这引起了麻烦。我不能说完全是因为我没有那么多的信息。

When you set it to www.yourdomain.com, there must have been some request to another subdomain, other than www. Which caused the trouble. I cannot say exactly because I don't have that much information.

这篇关于允许的主机在EC2上的设置的Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆