【发布时间】:2020-05-11 20:43:47
【问题描述】:
各位开发者,
出于对一切的热爱,我似乎无法让它工作......我有一个 docker 容器,其中运行着一个 phoenix 应用程序。它托管在子域“sub.example.com”上,我需要使用 https 来提供它。
所以我给自己弄了一个通配符 SSL 证书,安装了它,配置了生产文件并暴露了 docker 容器的 80 和 443 端口。
试过了,端口 80 工作正常,但 443 总是返回“ERR_CONNECTION_RESET”。日志在 443 上没有显示任何内容,但 80 工作正常。
已经尝试了一段时间,现在我需要你的帮助。有什么想法吗?检查下面的代码:
Dockerfile
FROM bitwalker/alpine-elixir-phoenix:latest
# create app folder
RUN mkdir /app
WORKDIR /app
COPY . .
# setting the port and the environment (prod = PRODUCTION!)
EXPOSE 80
EXPOSE 443
# install dependencies (production only)
RUN mix local.rebar --force
RUN mix deps.get --only prod
RUN mix compile
prod.exs
config :example, ExampleWeb.Endpoint,
http: [port: 80],
url: [host: "sub.example.com"],
cache_static_manifest: "priv/static/cache_manifest.json",
https: [
cipher_suite: :strong,
otp_app: :example,
port: 443,
keyfile: System.get_env("SSL_KEY_PATH"),
certfile: System.get_env("SSL_CERT_PATH"),
cacertfile: System.get_env("SSL_CHAINED_CERT_PATH")
]
curl https://sub.example.com/ --verbose 结果:
* Trying 64.225.24.82...
* TCP_NODELAY set
* Connected to sub.example.com (64.225.24.82) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to sub.example.com:443
* Closing connection 0
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to sub.example.com:443
编辑: 我正在手动设置容器内的 ENV 变量。例如在 bash 中:
SSL_KEY_PATH=path/example.key SSL_CERT_PATH=path/example.crt SSL_CHAINED_CERT_PATH=path/example_chained.crt MIX_ENV=prod mix phx.server
【问题讨论】:
-
您使用的是什么版本的 Phoenix?您在哪里设置 ENV 变量(
SSL_KEY_PATH、SSL_CERT_PATH和SSL_CHAINED_CERT_PATH)? -
您的
docker run命令是什么样的?您是否正确地将 EXPOSEd 端口映射到主机上的端口?您是否尝试将url的runtime config 设置为也包括scheme和port? -
@Everett 我目前正在使用
phoenix 1.4.13。我在启动时设置 ENV 变量。我的命令看起来像:SSL_KEY=path/to/it SSL_CERT=path/to/it mix phx.server. -
@jamesvl 我的 docker 运行命令是
docker run -it -p 80:80 -p 443:443 --entrypoint=bash --name example-app example:1.0。我也尝试过设置scheme和port。但没有成功:(。我一直在环顾四周,似乎我必须使用像 nginx 之类的代理服务器? -
当你运行
mix phx.server时,你是从你的主机操作系统运行它,还是你在 Dockerfile 的某个地方指定ENTRYPOINT?因为我没有看到您的 Docker 容器从哪里获取这些 ENV 值...
标签: docker ssl https elixir phoenix-framework