ドメイン名を介してサービスにアクセスできるようにし、別のポートを設定する必要がないようにTraefikを構成しようとしています。たとえば、2つのMongoDBサービスが両方ともデフォルトポートにありますが、異なるドメインにexample.localhostありexample2.localhostます。この例だけが機能します。つまり、他のケースはおそらく機能しますが、それらに接続できず、問題が何であるか理解できません。これはおそらくTraefikの問題でもありません。
動作する例を含むリポジトリを用意しました。mkcertを使用して独自の証明書を生成するだけです。のページexample.localhostは403 Forbiddenエラーを返しますが、この構成の目的はSSLが機能していることを示すこと(南京錠、緑のステータス)であるため、心配する必要はありません。したがって、に集中しないでください403。
mongoサービスへのSSL接続のみが機能します。Robo 3Tプログラムでテストしました。SSL接続を選択した後、ホストを提供example.localhostし、自己署名(または独自の)接続用の証明書を選択すると機能します。そして、それがそのように機能する唯一のものです。接続redis(Redisのデスクトップマネージャ)とするpgsql(PhpStorm、DBeaver、DbVisualizerのは)にかかわらず、私は証明書を提供するかどうかの、仕事をしないでください。SSLをサービスに転送せず、Traefikにのみ接続します。私はそれに長い時間を費やしました。インターネットを検索しました。まだ答えが見つかりません。誰かがこれを解決しましたか?
PS。私はLinux Mintで作業しているので、私の構成はこの環境で問題なく動作するはずです。Linuxの解決策を求めます。
リポジトリを参照したくない場合は、最も重要なファイルを添付します。
docker-compose.yml
version: "3.7"
services:
    traefik:
        image: traefik:v2.0
        ports:
            - 80:80
            - 443:443
            - 8080:8080
            - 6379:6379
            - 5432:5432
            - 27017:27017
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro
            - ./config.toml:/etc/traefik/traefik.config.toml:ro
            - ./certs:/etc/certs:ro
        command:
            - --api.insecure
            - --accesslog
            - --log.level=INFO
            - --entrypoints.http.address=:80
            - --entrypoints.https.address=:443
            - --entrypoints.traefik.address=:8080
            - --entrypoints.mongo.address=:27017
            - --entrypoints.postgres.address=:5432
            - --entrypoints.redis.address=:6379
            - --providers.file.filename=/etc/traefik/traefik.config.toml
            - --providers.docker
            - --providers.docker.exposedByDefault=false
            - --providers.docker.useBindPortIP=false
    apache:
        image: php:7.2-apache
        labels:
            - traefik.enable=true
            - traefik.http.routers.http-dev.entrypoints=http
            - traefik.http.routers.http-dev.rule=Host(`example.localhost`)
            - traefik.http.routers.https-dev.entrypoints=https
            - traefik.http.routers.https-dev.rule=Host(`example.localhost`)
            - traefik.http.routers.https-dev.tls=true
            - traefik.http.services.dev.loadbalancer.server.port=80
    pgsql:
        image: postgres:10
        environment:
            POSTGRES_DB: postgres
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: password
        labels:
            - traefik.enable=true
            - traefik.tcp.routers.pgsql.rule=HostSNI(`example.localhost`)
            - traefik.tcp.routers.pgsql.tls=true
            - traefik.tcp.routers.pgsql.service=pgsql
            - traefik.tcp.routers.pgsql.entrypoints=postgres
            - traefik.tcp.services.pgsql.loadbalancer.server.port=5432
    mongo:
        image: mongo:3
        labels:
            - traefik.enable=true
            - traefik.tcp.routers.mongo.rule=HostSNI(`example.localhost`)
            - traefik.tcp.routers.mongo.tls=true
            - traefik.tcp.routers.mongo.service=mongo
            - traefik.tcp.routers.mongo.entrypoints=mongo
            - traefik.tcp.services.mongo.loadbalancer.server.port=27017
    redis:
        image: redis:3
        labels:
            - traefik.enable=true
            - traefik.tcp.routers.redis.rule=HostSNI(`example.localhost`)
            - traefik.tcp.routers.redis.tls=true
            - traefik.tcp.routers.redis.service=redis
            - traefik.tcp.routers.redis.entrypoints=redis
            - traefik.tcp.services.redis.loadbalancer.server.port=6379
config.toml
[tls]
[[tls.certificates]]
certFile = "/etc/certs/example.localhost.pem"
keyFile = "/etc/certs/example.localhost-key.pem"
ビルドして実行
mkcert example.localhost # in ./certs/
docker-compose up -d
段階的に準備する
- mkcertをインストールします(mkcert -installCAの場合も実行)
- 私のクローンのコードを
- ではcerts、フォルダの実行mkcert example.localhost
- コンテナを開始 docker-compose up -d
- ページhttps://example.localhost/を開き、安全な接続かどうかを確認します
- アドレス場合のhttp://example.localhost/は到達できない、追加127.0.0.1 example.localhostに/etc/hosts
証明書:
- 公衆: ./certs/example.localhost.pem
- 民間: ./certs/example.localhost-key.pem
- CA: ~/.local/share/mkcert/rootCA.pem
MongoDBをテストする
- Robo 3Tをインストールする
- 新しい接続を作成します。
- 住所: example.localhost
- SSLプロトコルを使用する
- CA証明書:(rootCA.pemまたは自己署名証明書)
 
- 住所: 
- テストツール:
テストRedis
- RedisDesktopManagerをインストールする
- 新しい接続を作成します。
- 住所: example.localhost
- SSL
- 公開鍵: example.localhost.pem
- 秘密鍵: example.localhost-key.pem
- 権限: rootCA.pem
 
- 住所: 
- テストツール:
これまでのところ:
- IP経由でPostgresに接続できます(Traefikからの情報)
jdbc:postgresql://172.21.0.4:5432/postgres?sslmode=disablejdbc:postgresql://172.21.0.4:5432/postgres?sslfactory=org.postgresql.ssl.NonValidatingFactoryテレットを試してください(Dockerの再起動ごとにIPが変更されます):
> telnet 172.27.0.5 5432
Trying 172.27.0.5...
Connected to 172.27.0.5.
Escape character is '^]'.
^]
Connection closed by foreign host.
> telnet example.localhost 5432
Trying ::1...
Connected to example.localhost.
Escape character is '^]'.
^]
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad RequestConnection closed by foreign host.
postgresに直接接続すれば、データは素晴らしいです。Traefik経由でに接続すると、接続を閉じるときに不正なリクエストが発生します。これが何を意味するのか、それが何かを意味するのかどうかはわかりません。
Connections to redis (Redis Desktop Manager) ... do not work、しかしスクリーンショットは示していますSuccessful connection-?なぜ低レベルでテストしていないのcurl, openssl, telnet, ...ですか?netstatこれらのアプリポートが127.0.0.1インターフェイスでのトラフィック用に本当にバインドされているかどうかをテストしないのはなぜですか?
                



I can't connect to them->どのようにテストし、エラーは何でしたか?