Same location with different proxy urls nginx

We am trying to get nexus via nginx reverse proxy working as a private registry for docker images. We are able to perform all the operations such as pull,search and tag but not able to push to nexus registry .

Below is the nginx configuration under location block.

  • Where is information from dockerfile located?
  • can't open fuse device in a docker container when mounting a davfs2 volume
  • Issue executing python script in Docker
  • Getting User name + password to docker container
  • Why doesn't my pod respond to requests on the exposed port?
  • Why is Docker useful when running builds on slave nodes?
  •     location ~ ^/(v1|v2)/
        {
    
                access_log              /var/log/nginx/docker.log;
                proxy_set_header        Host $http_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-Proto "https";
                proxy_pass              http://server908.int.org.com:5555;
                proxy_read_timeout      90;
        }
    

    We are able to search and pull images.

    x.x.x.x - admin [23/Jun/2017:14:31:20 +0800] "GET /v1/search?q=fedora&n=25 HTTP/1.1" 200 3733 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    

    x.x.x.x - admin [23/Jun/2017:14:31:39 +0800] "GET /v2/fedora/apache/manifests/latest HTTP/1.1" 200 1362 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:40 +0800] "GET /v2/fedora/apache/manifests/sha256:8531786520bb57b155bbb39d3c670dceab554b9c4ccdb556ccfbe89b23df414c HTTP/1.1" 200 1362 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:40 +0800] "GET /v2/fedora/apache/blobs/sha256:c786010769a8fc7975e72c2b78f902425a6387fb5dda8852b3be2849e979e290 HTTP/1.1" 200 4094 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:40 +0800] "GET /v2/fedora/apache/blobs/sha256:4e81794d88f1b28cc1653df183400d08647143123a3f141fc8cab7cd97fc75e3 HTTP/1.1" 200 294 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:40 +0800] "GET /v2/fedora/apache/blobs/sha256:40da690b349860b5b2cf7cee231c21a04f1461a77ee542b77a2345412f521ae0 HTTP/1.1" 200 183 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:40 +0800] "GET /v2/fedora/apache/blobs/sha256:ebb42f0b0e1ad2d2ae815a6615b95bb59b925710df3db4b8fdb2f9fdaa14a806 HTTP/1.1" 200 294 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    x.x.x.x - admin [23/Jun/2017:14:31:42 +0800] "GET /v2/fedora/apache/blobs/sha256:8eea4f8b1da3e8c0848778a69e4ee73ad474a7be35fcc5ce7784a0b64ce711a7 HTTP/1.1" 200 57816237 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    

    But with push we face below error.

    x.x.x.x - admin [23/Jun/2017:14:32:34 +0800] "POST /v2/fedora/apache/blobs/uploads/?from=fedora%2Fssh&mount=sha256%3Aacd6cf67daf4cd1fcff55ece5a906a45e1569b81271b80136a1f5fecfa4546ed HTTP/1.1" 404 717 "-" "docker/1.12.6 go/go1.7.4 kernel/3.10.0-514.10.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.6 \x5C(linux\x5C))"
    

    when we try with proxy _pass url as http://server908.int.org.com:4444, we are able to push but cant pull the images .

    Is it possible in nginx to pass two different proxy_pass urls under the same location but for different request methods . Any help would be really great ..Thanks

  • Python - tlsv1 alert protocol version error in Docker client connection
  • Docker/virtualisation and HDFS
  • Cross-device link not permitted Error in Meteor Project with Docker
  • Cannot install plugin for IBM Container on Cloud Foundry on mac OS
  • Export on nodejs alpine docker image is not accepted
  • Sharing /etc/passwd between two Docker containers
  • 2 Solutions collect form web for “Same location with different proxy urls nginx”

    You can use if or map directives to select backend port.

    Note, that If is Evil, not in you case of course.

    location ~ ^/(v1|v2)/
    {
        set $port 5555;
        if ($request_method = POST) {
            set $port 4444;
        }
        access_log              /var/log/nginx/docker.log;
        proxy_set_header        Host $http_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-Proto "https";
        proxy_pass              http://server908.int.org.com:$port;
        proxy_read_timeout      90;
    }
    

    @sempasha : Thanks for you help . It working for me just with a minor tweak .
    Below is the location block added to get it working.

      location / {
    
          access_log              /var/log/nginx/docker.log;
          proxy_set_header        Host $http_host;
          proxy_set_header        X-Real-IP $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    
            if ($request_method !~* GET) {
                    proxy_pass              http://server908.int.org.com:4444;
            }
            if ($request_method = GET) {
                    proxy_pass              http://server908.int.org.com:5555;
            }
          proxy_read_timeout      90;
        }
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.