【问题标题】:How to set up SSL for container website in my condition (Apache2)如何在我的情况下为容器网站设置 SSL (Apache2)
【发布时间】:2021-06-10 16:05:41
【问题描述】:

The architecture of my website

我只想知道在我的情况下如何设置 SSL 以将 HTTP 更改为 HTTPS。我尝试遵循一些准则,但仍然失败……

是否有任何详细的说明/步骤来指导我在这样的环境中设置 SSL?

我在 apache2 中运行我所有的东西。

已经有域名了。

任何帮助将不胜感激...非常感谢...

【问题讨论】:

标签: docker ssl docker-compose containers apache2


【解决方案1】:

简答

  • 使用所需的关键字和命令(端口转发、命名、图像等)创建 docker-compose.ymlDockerfile 文件
  • 运行 Nginx 或 Apache 等 Web 服务器
  • 配置您的域配置文件
  • 在其中安装 certbot,让我们为您的域加密 SSL
  • 如果需要,在防火墙中打开所需的端口号(如果您配置了防火墙,则可能不需要此步骤)
  • 运行docker-compose up -d --build

长答案

docker-file.yml 内容(阅读更多Compose Docs

version: '3.9'

services:
    ANY_NAME:
        build: .
        restart: always
        ports:
            - 8201:8080
            - 8000:8101
    SECOND_NAME: # if you need more containers, copy this part
        build: .
        restart: always
        ports:
            - PORT_BE_ACCESSED_IN_WEB:LOCAL_PORT
volumes:
    SOME_NAME: {}

Docekrfile 内容(在Dockerfile Docs 阅读更多内容):

FROM nginx:latest # or any other base:version you need
# Your other commands goes there
# Example:
COPY ./domain.conf /etc/apache2/sites-available/
RUN a2ensite domain
RUN service apache2 reload
RUN apt-get update
RUN apt-get install certbot -y
RUN certbot ... # see certbot docs for more info
ENTRYPOINT ["some", "commands"]

然后运行这个命令,如果没有问题,应该没问题:

docker-compose up -d --build

现在应该可以通过http://your_server_ip:8201http://your_server_ip:8000 访问它。如果没问题,再检查https://your_server_ip:8201https://your_server_ip:8000

【讨论】:

  • 感谢您的回答。尝试后,我不小心删除了 etc/ssl 文件...我应该在 docker-file.yml 卷中放入什么?而且,我将 apache2 用于 docker 容器和 localhost。我还应该使用第一行“FROM nginx:latest”吗?我曾经使用 certbot 安装 SSL,但需要手动安装。在这种情况下,我还需要添加“RUN certbot”吗?最后, ENTRYPOINT ["some", "commands"] 中的 some, command 是什么意思?
  • 另外,什么是“cp ./domain.conf /etc/apache2/sites-available/”?
猜你喜欢
  • 2013-09-23
  • 1970-01-01
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 2011-05-22
  • 1970-01-01
  • 2011-04-20
相关资源
最近更新 更多