gpt4 book ai didi

ruby - 如何将 nginx 设置为 Ruby 应用程序的反向代理(全部在 Docker 中运行)

转载 作者:数据小太阳 更新时间:2023-10-29 08:08:12 25 4
gpt4 key购买 nike

我正在尝试使用 nginx 和 Ruby 应用程序设置一个简单的反向代理,但我也想在 Docker 容器内设置它。

我已经可以从 Docker 内部运行 Ruby 应用程序并从主机(我的 Mac OS X 使用 Boot2Docker)访问正在运行的服务。但是我现在一直在尝试实现 nginx 部分,因为我以前没有使用过它,而且似乎大多数关于该主题的文章/教程/示例都使用 Rails(而不是简单的 Sinatra/Rack 应用程序)并且还利用套接字 - 据我所知,我不需要它。

我也在使用 Docker Compose。

完整的目录结构如下:

├── docker-compose.yml
├── front-end
│   ├── Dockerfile
│   ├── Gemfile
│   ├── app.rb
│   ├── config.ru
├── proxy
│   ├── Dockerfile
│   ├── nginx.conf
│   └── public
│   ├── 500.html
│   ├── index.html

要查看这些文件的内容,请引用以下要点:

https://gist.github.com/Integralist/5cfd5c884b0f2c0c5d11

但是当我运行 docker-compose up -d 时,出现以下错误:

Creating clientcertauth_frontend_1...
Pulling image ./front-end:latest...
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 31, in main
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 21, in sys_dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 27, in dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 24, in dispatch
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 59, in perform_command
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 445, in up
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.project", line 184, in up
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 259, in recreate_containers
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 242, in create_container
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.client", line 824, in pull
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.auth.auth", line 67, in resolve_repository_name
File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.auth.auth", line 46, in expand_registry_url
docker.errors.DockerException: HTTPS endpoint unresponsive and insecure mode isn't enabled.

我不确定是什么导致了这个错误(一些谷歌搜索返回 https://github.com/docker/compose/issues/563 但据我所知这似乎是一个单独的问题?)。

如果我能克服这个错误,我也不完全确定 nginx.conf 是否设置正确。 nginx 的配置看起来应该正确地做一个反向代理(例如,使用 frontend 作为上游应用服务器,应该然后解析为前端的 docker ip 地址-终端容器 -> 如您所见,我已将两个容器链接在一起,因此我希望前端应用程序在代理容器的 /etc/hosts 中设置为别名) .

有人知道我可能遗漏了什么吗?

谢谢。

最佳答案

在您的要点中,您使用 image 作为键而不是 build,因此 docker-compose 试图从注册表中提取图像,但失败了。

由于您是在本地构建这些图像,因此您的 docker-compose.yml 文件的语法应如下所示:

frontend:
build: front-end/
ports:
- "8080:5000"

关于ruby - 如何将 nginx 设置为 Ruby 应用程序的反向代理(全部在 Docker 中运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30033647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com