events {
    worker_connections 16;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    error_log /dev/stdout info;
    access_log /dev/stdout;

    server {
        listen *:5000 ssl;
        server_name test-registry.ansible.com;
        server_name_in_redirect on;

        ssl_protocols TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256';
        ssl_ecdh_curve X25519:secp521r1:secp384r1;
        ssl_prefer_server_ciphers on;
        ssl_certificate /etc/nginx/cert.pem;
        ssl_certificate_key /etc/nginx/cert.key;

        location / {
            return 401;
        }

        location /v2/ {
            proxy_pass  http://real-registry:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Request-Start $msec;

            client_max_body_size 0;
            chunked_transfer_encoding on;

            auth_basic "Ansible Test Docker Registry";
            auth_basic_user_file /etc/nginx/nginx.htpasswd;
        }
    }
}