使用 docker、ALLOWED_HOSTS 部署 Django 应用程序
Deploying django app with docker, ALLOWED_HOSTS
我正在尝试 运行 一个带有 docker 的 django 应用程序,我正在使用现有的 cookiecutter-django template。但是,当尝试 运行 应用程序时,出现以下错误:
错误请求 (400)
从终端查看日志时,我看到以下内容:
django_1 | [2015-12-18 17:08:04 +0000] [15] [INFO] Booting worker with pid: 15
django_1 | [2015-12-18 17:08:04 +0000] [16] [INFO] Booting worker with pid: 16
django_1 | [2015-12-18 17:08:04 +0000] [18] [INFO] Booting worker with pid: 18
django_1 | [2015-12-18 17:08:04 +0000] [20] [INFO] Booting worker with pid: 20
django_1 | ERROR 2015-12-18 18:08:07,072 base 18 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:08 +0000] "GET /admin HTTP/1.1" 400 37 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
django_1 | ERROR 2015-12-18 18:08:08,570 base 20 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:09 +0000] "GET /favicon.ico HTTP/1.1" 400 37 "http://192.168.99.100/admin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
django_1 | ERROR 2015-12-18 18:08:09,842 base 18 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:11 +0000] "GET /favicon.ico HTTP/1.1" 400 37 "http://192.168.99.100/admin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
这很奇怪,因为我已经将 192.168.99.100 添加到 ALLOWED_HOSTS(也尝试了 ["*"]),所以我不太明白这个错误是从哪里来的。
所以最后括号产生了错误,因为主机是在我的环境变量中设置的。添加不带括号的 *
(或实际主机)有效。
我正在尝试 运行 一个带有 docker 的 django 应用程序,我正在使用现有的 cookiecutter-django template。但是,当尝试 运行 应用程序时,出现以下错误:
错误请求 (400)
从终端查看日志时,我看到以下内容:
django_1 | [2015-12-18 17:08:04 +0000] [15] [INFO] Booting worker with pid: 15
django_1 | [2015-12-18 17:08:04 +0000] [16] [INFO] Booting worker with pid: 16
django_1 | [2015-12-18 17:08:04 +0000] [18] [INFO] Booting worker with pid: 18
django_1 | [2015-12-18 17:08:04 +0000] [20] [INFO] Booting worker with pid: 20
django_1 | ERROR 2015-12-18 18:08:07,072 base 18 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:08 +0000] "GET /admin HTTP/1.1" 400 37 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
django_1 | ERROR 2015-12-18 18:08:08,570 base 20 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:09 +0000] "GET /favicon.ico HTTP/1.1" 400 37 "http://192.168.99.100/admin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
django_1 | ERROR 2015-12-18 18:08:09,842 base 18 140496642320128 Invalid HTTP_HOST header: '192.168.99.100'. You may need to add '192.168.99.100' to ALLOWED_HOSTS.
nginx_1 | 192.168.99.1 - - [18/Dec/2015:17:08:11 +0000] "GET /favicon.ico HTTP/1.1" 400 37 "http://192.168.99.100/admin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"
这很奇怪,因为我已经将 192.168.99.100 添加到 ALLOWED_HOSTS(也尝试了 ["*"]),所以我不太明白这个错误是从哪里来的。
所以最后括号产生了错误,因为主机是在我的环境变量中设置的。添加不带括号的 *
(或实际主机)有效。