【问题标题】:nginx docker compose not up and runningnginx docker compose 未启动并运行
【发布时间】:2021-10-29 15:39:52
【问题描述】:

我有下面的 docker-compose 用于 nginx 服务:但是我没有看到任何服务请求转发的启动和运行,我做错了什么吗?任何建议都会很有帮助。

container_name: nginx
    image: nginx
    ports:
      - 80:80
      - 443:443
    entrypoint: /bin/sh -c
    command: >
      cat << EOF > /etc/nginx/conf.d/myproxy.conf
      server {
        listen 80;
        listen 443 ssl;
        ssl_certificate    /etc/nginx/my.com.cert;
        ssl_certificate_key    /etc/nginx/my.com.key;
        server_name my.app.com;
        location / {
          proxy_pass http://service-name:443;
          }
        }
      EOF
      nginx -s reload;
      nginx -g 'daemon off;'
    volumes:
      - ./nginx/my.com.key:/etc/nginx/my.com.key
      - ./nginx/my.com.cert:/etc/nginx/my.com.cert
    networks:

nginx 应该启动并运行,但我没有看到任何用于 Nginx 的容器。


已解决:

我通过创建包含所有服务器详细信息的自定义 conf 文件并将该自定义 conf 文件映射到覆盖现有 conf 以及已删除的入口点和命令块来解决了这个问题。

【问题讨论】:

  • nginx -s reload 可能有问题,因为此时 nginx 没有运行。当您运行docker-compose up(没有-d)时,它应该在日志中可见。顺便说一句,您可以将配置保存在文件中并将其与 SSL 证书和密钥一起安装。这样您就不必在启动时编写配置。
  • 是的,我现在正在安装它。 ;-)

标签: nginx docker-compose


【解决方案1】:

首先,去掉整个命令和入口部分! :)。 将您的 nginx 配置写入 docker-compose.yml 旁边的文件中或您想要的任何位置(让我们将其命名为 myproxy.conf)。然后,将./myproxy.conf:/etc/nginx/conf.d/myproxy.conf 添加到值部分。
Nginx docker images 自己处理入口点,无需干预!

你的作曲应该是这样的:

  nginx:
    container_name: nginx
    image: nginx
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./myproxy.conf:/etc/nginx/conf.d/myproxy.conf
      - ./nginx/my.com.key:/etc/nginx/my.com.key
      - ./nginx/my.com.cert:/etc/nginx/my.com.cert
    networks:

【讨论】:

  • 谢谢,@mohammad Hosein 我也是这么做的。
猜你喜欢
  • 2021-01-13
  • 2019-11-13
  • 2022-06-20
  • 2021-09-23
  • 2016-01-05
  • 1970-01-01
  • 2021-12-01
  • 2018-05-16
  • 1970-01-01
相关资源
最近更新 更多