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相关推荐

  1. python3 django配置数据库(mysql)

    python3 django配置数据库(mysql)http://www.bieryun.com/3311.html python3 下的mysql驱动 django 连接mysql默认驱动是MySQ ...

  2. Django配置Mysql数据库连接

    Django配置Mysql数据库连接 前言 Django原生自带的数据库支持是sqlite,但是我们现在常用的数据库一般是mysql,mangodb等数据库.所以我们要改变数据库的链接,从而达到使用m ...

  3. Django配置MySQL执行python manage.py makemigrations 出现No changes detected报错

    在给Django配置mysql的时候按照教程在Model.py文件中配置加入定义模型类的代码后 执行数据迁移代码 python manage.py makemigrations 报错 显示No cha ...

  4. Nginx+UWSGI+Django配置全过程

    Nginx + uwsgi + Django 安装配置 一.安装Nginx uwsgi Django 安装tengine yum install pcre-devel -y wget http://t ...

  5. Nginx +uwsgi+django配置

    Nginx+uwsgi+django配置 nginx配置 nginx.conf 一般位于linux系统的 /etx/nginx/ 目录下 upstream django {server unix:// ...

  6. django配置mysql,并解决NameError: name ‘_mysql‘ is not defined报错

    首先需要安装好mysql,然后修改django的setting.py 将原始的: DATABASES = {'default': {'ENGINE': 'django.db.backends.sqli ...

  7. 微信抢票环境配置——nginx + uwsgi + django配置服务器

    微信抢票环境配置--nginx + uwsgi + django配置服务器 1 uwsgi配置 2 http协议(80端口)下的nginx配置 1 uwsgi配置 安装uwsgi pip3 insta ...

  8. Python3.7中,Django配置MySql数据库

    上一节中讲了Python3.7搭建Django框架项目 ,并且项目能够运行起来,Django框架中默认配置的数据库是sqlite,sqlite数据库虽然小巧,但是对于大型项目时sqlite就会有瓶颈, ...

  9. Django配置163邮箱出现 authentication failed(535)错误解决方法

    2019独角兽企业重金招聘Python工程师标准>>> 最近用Django写某网站,当配置163邮箱设置完成后,出现535错误即:smtplib.SMTPAuthentication ...

  10. Django启航(四)Django配置数据库

    文章目录 Django启航(四)Django配置数据库与测试 1. 基础配置 1.1 打开之前的项目 1.2 安装pymysql 1.3 配置settings文件 1.4 引入pymysql 2. 测 ...

最新文章

  1. Python发送邮件smtplib.SMTP各报错问题的解决方法
  2. 计算机反面的考研专业,2018计算机考研:历年准考证打印常见七大问题
  3. 评估模型如何建立_建立和评估分类ML模型
  4. c语言goto语句用法_C语言32个关键字9种控制语句34种运算符整理
  5. 嵌入式知识概要(1)
  6. Rational Rose :从用例图开始
  7. c# 类属性和方法
  8. TensorFlow基础篇(二)——tf.get_variable()和tf.get_variable_scope()
  9. C++基础::非类型模板参数在STL中的应用
  10. python使用缩进来体现-Python 使用缩进来体现代码之间的逻辑关系 .
  11. Android 插件化 动态升级
  12. IOS7开发~Xcode5制作framework
  13. Github copilot: AI协助编程尝试
  14. VideoPlayer参数
  15. DevOps定义基础入门及历史
  16. 百度AI认为最漂亮的中国女星是----范冰冰
  17. python搜索引擎根据关键词爬取内容
  18. AD20 指定层PCB图纸1:1打印步骤笔记
  19. Hive基础学习文档和入门教程
  20. 学学Gnuplot(常用命令及参数)

热门文章

  1. SCI论文撰写——Conclusion
  2. 服务器 ssd虚拟内存,ssd虚拟内存设多大
  3. 免费网络视频监控软件cmsclient
  4. 再迎顶尖科学家,百度研究院为何如此吸引大师级AI人才?
  5. 什么是递归?递归的理解
  6. 从 API、UI、结构到商业产品设计精髓
  7. 实例讲解kubernetes网络通信
  8. 什么是驻点和拐点_临界点、驻点、拐点的定义是什么?
  9. Android JNI:lame库的编译及使用
  10. 大学毕业生如何成功应聘高薪IT职位 [转]