0

How can I use client certificate authentication with nginx for a folder? The ssl_client_certificate directive isn't allowed in location blocks. Example: I want my website me.tld to be reachable by all clients and everything below me.tld/secure/ only by authenticated clients.

2

I'm not in a position to try this myself but you could try the following

You will need ssl_verify_client optional; to go along side ssl_client_certificate and then use the following location block

location /secure {
    error_page 418 = @other;
    recursive_error_pages on;
    if ($ssl_client_verify = SUCCESS) {
    return 418
    }

location @other {
    #Secure Config goes here
    }

The client certificate will be checked but not enforced for all locations. When someone tries the /secure directory nginx will then check to see if $ssl_client_verify was successful at the server level. If it was it will return error 418 which we told nginx to deal with in the @other location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.