django配置(setting)之ALLOWED_HOSTS
django配置(setting)之ALLOWED_HOSTS
django官方文档解释:
ALLOWED_HOSTS¶
Default: [] (Empty list)A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.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. A value of '*' will match anything; in this case you are responsible to provide your own validation of the Host header (perhaps in a middleware; if so this middleware must be listed first in MIDDLEWARE).Django also allows the fully qualified domain name (FQDN) of any entries. Some browsers include a trailing dot in the Host header which Django strips when performing host validation.If the Host header (or X-Forwarded-Host if USE_X_FORWARDED_HOST is enabled) does not match any value in this list, the django.http.HttpRequest.get_host() method will raise SuspiciousOperation.When DEBUG is True and ALLOWED_HOSTS is empty, the host is validated against ['localhost', '127.0.0.1', '[::1]'].This validation only applies via get_host(); if your code accesses the Host header directly from request.META you are bypassing this security protection.Changed in Django 1.10.3:
In older versions, ALLOWED_HOSTS wasn’t checked if DEBUG=True. This was also changed in Django 1.9.11 and 1.8.16 to prevent a DNS rebinding attack.
理解AllOWED_HOSTS
settings.py
注意:
settings.py
设置文件只是一个带有模块级别变量的Python模块。
- 由于
settings.py
设置文件时Python模块,因此以下内容适用:- 它不允许Python语法错误。
- 它可以使用普通的Python语法动态分配设置。例如:
MY_SETTING = [str(i) for i in range(30)]
。 - 它可以从其他设置文件导入值。
ALLOWED_HOSTS的作用
ALLOWED_HOSTS
是为了限定请求中的host
值,以防止黑客构造包来发送请求。只有在列表中的host
才能访问。
注意:在这里本人强烈建议不要使用
*
通配符去配置,另外当DEBUG
设置为False
的时候必须配置这个配置。否则会抛出异常。
ALLOWED_HOSTS的配置中文说明
ALLOWED_HOSTS
后面所跟的属性值是一个字符串列表值,这个字符串列表值表示当下这个Django站点可以提供的host/domain
(主机/域名)。这是一种安全措施,通过使用伪造的HTTP主机标头提交请求来防止攻击者中毒缓存并触发带有恶意主机链接的密码重置电子邮件,即使在许多看似安全的Web服务器配置下也是如此。
django配置(setting)之ALLOWED_HOSTS相关推荐
- python3 django配置数据库(mysql)
python3 django配置数据库(mysql)http://www.bieryun.com/3311.html python3 下的mysql驱动 django 连接mysql默认驱动是MySQ ...
- Django配置Mysql数据库连接
Django配置Mysql数据库连接 前言 Django原生自带的数据库支持是sqlite,但是我们现在常用的数据库一般是mysql,mangodb等数据库.所以我们要改变数据库的链接,从而达到使用m ...
- Django配置MySQL执行python manage.py makemigrations 出现No changes detected报错
在给Django配置mysql的时候按照教程在Model.py文件中配置加入定义模型类的代码后 执行数据迁移代码 python manage.py makemigrations 报错 显示No cha ...
- Nginx+UWSGI+Django配置全过程
Nginx + uwsgi + Django 安装配置 一.安装Nginx uwsgi Django 安装tengine yum install pcre-devel -y wget http://t ...
- Nginx +uwsgi+django配置
Nginx+uwsgi+django配置 nginx配置 nginx.conf 一般位于linux系统的 /etx/nginx/ 目录下 upstream django {server unix:// ...
- django配置mysql,并解决NameError: name ‘_mysql‘ is not defined报错
首先需要安装好mysql,然后修改django的setting.py 将原始的: DATABASES = {'default': {'ENGINE': 'django.db.backends.sqli ...
- 微信抢票环境配置——nginx + uwsgi + django配置服务器
微信抢票环境配置--nginx + uwsgi + django配置服务器 1 uwsgi配置 2 http协议(80端口)下的nginx配置 1 uwsgi配置 安装uwsgi pip3 insta ...
- Python3.7中,Django配置MySql数据库
上一节中讲了Python3.7搭建Django框架项目 ,并且项目能够运行起来,Django框架中默认配置的数据库是sqlite,sqlite数据库虽然小巧,但是对于大型项目时sqlite就会有瓶颈, ...
- Django配置163邮箱出现 authentication failed(535)错误解决方法
2019独角兽企业重金招聘Python工程师标准>>> 最近用Django写某网站,当配置163邮箱设置完成后,出现535错误即:smtplib.SMTPAuthentication ...
- Django启航(四)Django配置数据库
文章目录 Django启航(四)Django配置数据库与测试 1. 基础配置 1.1 打开之前的项目 1.2 安装pymysql 1.3 配置settings文件 1.4 引入pymysql 2. 测 ...
最新文章
- Python发送邮件smtplib.SMTP各报错问题的解决方法
- 计算机反面的考研专业,2018计算机考研:历年准考证打印常见七大问题
- 评估模型如何建立_建立和评估分类ML模型
- c语言goto语句用法_C语言32个关键字9种控制语句34种运算符整理
- 嵌入式知识概要(1)
- Rational Rose :从用例图开始
- c# 类属性和方法
- TensorFlow基础篇(二)——tf.get_variable()和tf.get_variable_scope()
- C++基础::非类型模板参数在STL中的应用
- python使用缩进来体现-Python 使用缩进来体现代码之间的逻辑关系 .
- Android 插件化 动态升级
- IOS7开发~Xcode5制作framework
- Github copilot: AI协助编程尝试
- VideoPlayer参数
- DevOps定义基础入门及历史
- 百度AI认为最漂亮的中国女星是----范冰冰
- python搜索引擎根据关键词爬取内容
- AD20 指定层PCB图纸1:1打印步骤笔记
- Hive基础学习文档和入门教程
- 学学Gnuplot(常用命令及参数)