大网数据广告活动
服务器运维问答

Nginx SSL auth curtain client certificate

· 52CE 我爱测

I have working Nginx with TLS authentication with following configuration. All request with valid client certificates will be terminated at Nginx and request will be forwarded to backend app. upstream app { server app:8080; } ser…

问题原文

原帖链接 · rp346 · CC BY-SA 4.0

I have working Nginx with TLS authentication with following configuration. All request with valid client certificates will be terminated at Nginx and request will be forwarded to backend app.


    upstream app {
        server app:8080;
    }

    server {
        listen                 443 ssl;
        server_name            localhost;
        ssl_certificate        /etc/ssl/cert_example_com.crt;
        ssl_certificate_key    /etc/ssl/cert_example_com.key;
        ssl_client_certificate /etc/ssl/ca.crt;
        ssl_protocols          TLSv1.2 TLSv1.3;
        ssl_ciphers            HIGH:!aNULL:!MD5;
        ssl_verify_client      on;

        location / {
                proxy_pass         http://app;
                proxy_set_header   X-Forwarded-For $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header   Upgrade $http_upgrade;
                proxy_set_header   Connection 'upgrade';
                proxy_set_header   Host $host;
                proxy_cache_bypass $http_upgrade;
        }
    }

With this configuration I want Nginx to authenticate only certain client certificates. This is because I am using Private RootCA to generate Type A certs and Type B certs. Type A certs are used with MQTT for auth & Type B certs are used for Nginx (HTTPS) authentication.

client certificate (Type A) for MQTT will be unique for each client <UUID>.example.com. client certificate (Type B) for Nginx will have name (DN) base.example.com & certificate will be shared among multiple clients. Aslo there will be limited number of Type B certificates active at a time with same name (DN) base.example.com and different certificate ID.

any help on this how I can possibly achieve this ?

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 4.0

All of the certificates will be validated, but you can still reject requests from connections using the other certificates by checking the DN of the client certificate.

For example:

server {
    if ($ssl_client_s_dn !~ \bbase\.example\.com\b) { return 403; }
    ...
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-05-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。