运行 带有 Apache 2.4 mod_proxy 和基本身份验证的 Docker 容器中的 Portainer

Running Portainer in a Docker Container with Apache 2.4 mod_proxy and basic auth

问:如何使用基本身份验证将 Apache 2.4 配置为 Portainer 的反向代理?

Portainer 是一个 UI 用于管理 Docker 容器。 Portainer 文档有一个示例 nginx configuration,但不幸的是 none 用于 apache。

A:您需要使用标志 --no-auth 启动 Portainer 并使用 mod_proxy_wstunnel.

使用 --no-auth 启动 Portainer。 我使用以下 Docker 撰写文件:

portainer:
  image: portainer/portainer
  container_name: "portainer-app"
  privileged: true
  command: --no-auth
  ports:
    - 9000:9000
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /srv/docker/portainer/data:/data
    - /etc/localtime:/etc/localtime:ro
    - /etc/timezone:/etc/timezone:ro
  environment:
    TZ: "Europe/Berlin"

为您的 Apache 域配置基本身份验证。 启用 mod_proxy_wstunnel。 将以下内容添加到配置中:

<Location /portainer/>
    ProxyPass http://localhost:9000/
    ProxyPassReverse http://localhost:9000/
    RequestHeader set Connection ""
</Location>
<Location /portainer/api/websocket/>
    RequestHeader set Upgrade $http_upgrade;
    RequestHeader set Connection "upgrade"
    ProxyPass ws://localhost:9000/api/websocket/
</Location>

我在 Docker Swarm 中安装了 Portainer,带有 Docker Flow Proxy,全部在 Apache 后面。

按照this的想法,我成功配置了apache。

<Location /portainer/api/websocket/>
  RewriteEngine On
  RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
  RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
  RewriteRule /portainer/api/websocket/(.*) ws://192.168.1.190:480/portainer/api/websocket/ [P]
</Location>