Nginx proxy to couchdb

Trying to put together a compose setup using an nginx proxy to couchdb.

I can get this to work swimmingly well in a VM environment, but I can’t get it to work in docker - with curl on the host to localhost:8085, I get ‘(52) Empty reply from server’. Nothing is showing up in the log output, nor is anything showing in the nginx access/error logs in the container.

Here is my docker-compose file:

version: "3"
    container_name: db.list-2-list.lcldev
    build: ./db.list-2-list/dev
      - "8085:80"
      - backend
      - frontend
      - ./db.list-2-list/dev/conf.d:/etc/nginx/conf.d

    container_name: "aph-couchdb"
    image: "aph/couchdb"
      - backend
      - cb-combined:/opt/couchdb/data


      name: "cb-combined"

The ‘aph-coucdb’ container is derived from the apache couchdb image - It just contains my local.ini file (substituting the apache couchdb image with default config shows the same results.)

Port 5984 is exposed in the base image, so I’m not exposing it here (although I have tried that.) If I add a ports entry to the couchdb service exporting 5984:5984, then I can talk to the couchdb container directly, and all seems fine with it. I can also exec into the nginx container, and ping/curl aph-couchdb with expected results.

Here’s my nginx config:

server {
  listen 80 default;
# listen [::]:80;
  location / {
    proxy_pass aph-couchdb:5984;
    proxy_redirect off;
#    proxy_set_header Host $host;
#    proxy_set_header X-Real-IP $remote_addr;
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#    proxy_set_header X-Forwarded-Host $server_name;
#    proxy_hide_header X-Powered-By;
    if ($request_method = OPTIONS ) {
      add_header 'Access-Control-Allow-Origin' '$http_origin';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, HEAD, DELETE, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'X-Auth-CouchDB-UserName,X-Auth-CouchDB-Roles,X-Auth-CouchDB-Token,Accept,Authorization,Origin,Referer,X-Csrf-Token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Max-Age' 86400;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;

  location ~ ^/(.*)/_changes {
    proxy_pass aph-couchdb:5984;

The commented out entries are various things I’ve tried based on other research - none make a difference - I still get the (52) Empty reply from server when I curl localhost:8085 from the host.

Can’t seem to get any further on this…

Thoughts appreciated.

A Container name is neither a service name, nor a hostname. nor an network alias. Afaik, it is only used to give the container a friendly name for operations with the docker cli (or other management tools)

You either need to add a hostname or network-alias to the coudb container OR modify the proxy_pass setting of your nginx configuration to point to the service name, which is couchdb and not aph-couchdb.

Hey, belated thanks for the response. I had to leave this to work on something else and now I’m getting my head back into it

Update: Ack. Realized that my nginx configuration file didn’t have a .conf suffix, which is what the main configuration is looking for in the include directive. So, it wasn’t even getting my config file. Fixed that, restored the original nginx configuration, and voila!! Works like a champ.

So, per your comment I changed the proxy pass to the service name, rather than add a hostname to the aph-couchdb container. That’s the easiest.

Onward to the next sticking point.