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

ssl_verify_client for all paths except some

· 52CE 我爱测

I have a server running on a subdomain configured like so: server { listen 80 default_server; listen [::]:80 default_server; server_name x.example.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; liste…

问题原文

原帖链接 · Scott Colby · CC BY-SA 3.0

I have a server running on a subdomain configured like so:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name x.example.com;

  return 301 https://$server_name$request_uri;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;

  <ssl configuration from https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=no&profile=modern>

  ssl_client_certificate /etc/ssl/certs/root-ca.crt;
  ssl_verify_client on;
  ssl_verify_depth 2;

  root /var/www/html;
  index index.html index.htm;

  location / {
    try_files $uri $uri/ =404;
  }
}

Currently, I'm using my own root CA both for the client verification and as the server's main certificate. I'd like to transition to using a Let's Encrypt certificate, but this poses a problem, since the Let's Encrypt verification process will require access to x.example.com/.well-known and will not have a matching client certificate.

I've tried adding a second server block like so, as recommended here, but I haven't been able to get it to work:

server {
  listen 443 ssl;
  listen [::]:443 ssl;

  server_name x.example.com;

  <same Mozilla configuration--I've got it stored as a snippet>

  ssl_verify_client off;

  root /var/www/html;
  index index.html index.htm;

  location /.well-known {
    try_files $uri $uri/ =404;
  }
}

What is an appropriate way to do this?

已采纳解答

原帖链接 · Ginnungagap · CC BY-SA 3.0

Let's Encrypt doesn't look for challenges on HTTPS so you may simply set up something like this:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name x.example.com;

    location /.well-known {
        try_files $uri $uri/ =404;
    }

    location / {
        return 301 https://$server_name$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    <ssl configuration from https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=no&profile=modern>

    ssl_client_certificate /etc/ssl/certs/root-ca.crt;
    ssl_verify_client on;
    ssl_verify_depth 2;

    root /var/www/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}

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

资料来源与适用范围

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

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

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