1

I have a Nexus Repository Manager OSS 3.0 running behind NGINX as a private docker registry. My Docker client (not the official docker client) is expecting a 200 OK and an empty JSON string {} to be returned from /v2/. The problem i'm running into is that Nexus returns the 200 OK but an empty string.

My work-around is to have NGINX return a file containing an empty JSON string for /v2/ requests and proxy /v2/* requests to Nexus.

server {
  listen               443 ssl;
  server_name          nexus.example.com;
  ssl_certificate      ssl/server.crt;
  ssl_certificate_key  ssl/server.key;

  location = /v2/ {
    root /home/ubuntu/www;
    index empty.json;
  }

  location /v2/ {
    proxy_pass                          http://localhost:5000;
    proxy_set_header  Host              $http_host;   # required for docker client's sake
    proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
    proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_read_timeout                  900;
  }
}

I would expect this to work, but it directs all traffic (/v2/, /v2/_catalog, /v2/myimage/manifests/latest, etc) to the proxy_pass. How can I make /v2/ requests go to the location to sever the empty.json file?

Patrick Crocker
  • 193
  • 2
  • 6

1 Answers1

1

So you have placed a file at /home/ubuntu/www/v2/empty.json?

The problem is that the index directive will rewrite the URI to /v2/empty.json which is then processed by the location /v2/ block.

One solution would be to create another location to match the rewritten URI and serve it as a static file:

root /home/ubuntu/www;

location = /v2/ {
    index empty.json;
}
location = /v2/empty.json {
}

Another solution is to use the error_page directive. But you will still need to specify a location and root to handle the static file(s):

location = /v2/ {
    return 405;
    error_page 405 =200 /static/empty.json;
}
location / {
    root /home/ubuntu/www;
}
Richard Smith
  • 45,711
  • 6
  • 82
  • 81