apache / couchdb-docker

Semi-official Apache CouchDB Docker images
https://github.com/apache/couchdb-docker
Apache License 2.0
263 stars 136 forks source link

Change port not working for reverse proxy #254

Open key262yek opened 8 months ago

key262yek commented 8 months ago

I setup couchdb via rootless docker on Ubuntu 22.04, docker v25.0.3 with following compose

couchdb:
    image: couchdb:3.3.3
    container_name: couchdb
    restart: unless-stopped
    ports:
      - "9564:5984"
    networks:
      - monitoring
    environment:
      - COUCHDB_USER
      - COUCHDB_PASSWORD
    volumes:
      - couchdb_data:/opt/couchdb/data    
      - ./couchdb/local.ini:/opt/couchdb/etc/local.ini

As you can see, I change the port from 5984 to other. It runs fine, and I can access Fauxton via http://localhost:9564/_utils

Since I want to reverse proxy db, I wrote haproxy.cfg

backend couchdb-http
        mode http
        balance roundrobin
        option httpchk GET /_up
        http-check disable-on-404
        server couchdb localhost:9564 check inter 5s
        timeout connect 4s
        timeout server 4s

frontend redirect
        mode http
        bind :::80 v4v6
        bind :::443 v4v6 ssl crt /etc/haproxy/certs/domain.pem

        http-request redirect scheme https code 301 unless { ssl_fc }
        http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"

        http-request set-header Host %[req.hdr(Host)]
        http-request set-header X-Forwarded-Proto https if { ssl_fc }

        use_backend couchdb-http

        timeout client 4s

But it fails with error couchdb-http/couchdb is DOWN, reason: Layer7 wrong status, code: 401, info: "Unauthorized"

If I change the port in backend from 9564 to 5984, it works.

Add I can access both of two following addresses

>> curl localhost:5984
{"error":"unauthorized","reason":"Authentication required."}
>> curl localhost:9564
{"error":"unauthorized","reason":"Authentication required."}

Even if I change the chttpd port in fauxton configuration page, its behavior is same. (Should I restart after change configuration?)

Expected Behavior

Reverse proxy works with port 9564

Current Behavior

Reverse proxy works only with port 5984 even if I changed port in compose.yaml

Possible Solution

Steps to Reproduce (for bugs)

  1. run docker with different port from 5984
  2. reverse proxy with changed port
  3. Get "Unauthorized" error

Context

Your Environment