-
-
Save tonyclemmey/4924feff6efaa19a768380dbf585656f to your computer and use it in GitHub Desktop.
CN-based client authentification with nginx. This emulates Apache's SSLRequire (%{SSL_CLIENT_S_DN_CN} in {"Really Me"})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $ssl_client_s_dn $ssl_client_s_dn_cn { | |
default ""; | |
~/CN=(?<CN>[^/]+) $CN; | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
server_name foo.bar.com; | |
if ($scheme = http) { | |
return 301 https://$server_name$request_uri; | |
} | |
ssl_certificate /etc/ssl/$server_name; | |
ssl_certificate_key /some/where/private; | |
ssl_client_certificate /the/root/of/all/client/cas.pem | |
ssl_verify_depth 3; | |
ssl_verify_client optional; | |
location ~ ^/safe { | |
if ($ssl_client_verify != SUCCESS) { | |
return 401; | |
} | |
if ($ssl_client_s_dn_cn !~ "Really Me") { | |
return 401; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment