如何从 docker 容器通过 https 服务 Kinto?

How do I serve Kinto via https from a docker container?

正如 Kinto 文档中所写,我可以 specify a custom configuration 这样:

docker run --env-file ./kinto.env -p 8888:8888 kinto/kinto-server.

此外,我似乎可以 suggest an http scheme 使用 http_scheme 属性.

现在,如果我:

  1. KINTO_HTTP_SCHEME=https放入kinto.env文件;
  2. 运行 Kinto 通过上面的命令,和;
  3. 转到https://example.com:8888/v1/

我得到一个空白页。

附加信息

如果我导航到 http://example.com:8888/v1/,我会在页面上看到通常的 JSON 配置。此 JSON 还包含 url 属性 这是 https://example.com:8888/v1/(而不是 http://example.com:8888/v1/),所以似乎发生了一些事情:读取了 .env 文件。 link 是可点击的,但如果我点击它,我仍然得到一个空白页面。

这是一个错误吗?我该如何解决这个问题?


备注

这很重要,因为如果页面是通过 https 提供的,Chrome 将不允许我提供 http 内容。它完全阻止了请求,并在控制台中显示相应的错误:d Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure resource 'http://example.com:8888/v1/'. This request has been blocked; the content must be served over HTTPS.

Kinto 说:Fetch API cannot load http://example.com:8888/v1/. Failed to start. Error: HTTP 0; TypeError: Failed to fetch(…)

从未使用过 Kinto,但来自 documentation:

The environment variables are exactly the same as the settings, but they > are capitalised and . are replaced by _.

For example, kinto.storage_backend is read from environment variable KINTO_STORAGE_BACKEND if defined.

因此,您要在 kinto.env 文件中设置的 environment variableKINTO_HTTP_SCHEME,而不是 HTTP_SCHEME

这取决于你如何 运行 Kinto。 pserve 默认使用女服务员服务器,它没有任何 HTTPS 支持。

可以使用替代服务器(例如 gunicorn 或 uwsgi)来替代 pserve,方法是在 .ini 文件中指定它。

以下是正确文档的指针:

例如,独角兽看起来像这样:

[server:main]
use = egg:gunicorn
host = 0.0.0.0
port = 5900
workers = 1
worker_class = gevent

然后配置 gevent 来执行 SSL:

certfile=~/ssl/server.crt
keyfile=~/ssl/server.key
ssl_version=3

对于uwsgi,你在文档中有默认配置,见http://kinto.readthedocs.org/en/latest/configuration/production.html?highlight=uwsgi#运行ning-与-uwsgi

希望对您有所帮助。

或者,您可以使用 NGINX 或 haproxy 为您完成 SSL 终止。