大网数据广告活动
网站运营与故障问答

Reverse proxy SSL with Nginx, do I need a wildcard or a separate cert for every host?

· 52CE 我爱测

I have Nginx setup and successfully serving SSL to example.com using certbot/letsencrypt. But when I try to reverse proxy to a local machine I get NET::ERR_CERT_COMMON_NAME_INVALID . Here's the basic setup role name ip Nginx serv…

问题原文

原帖链接 · THE JOATMON · CC BY-SA 4.0

I have Nginx setup and successfully serving SSL to example.com using certbot/letsencrypt. But when I try to reverse proxy to a local machine I get NET::ERR_CERT_COMMON_NAME_INVALID. Here's the basic setup

role name ip
Nginx server example.com 192.168.1.1
Web server test01.example.com 192.168.1.10
Web server test02.example.com 192.168.1.11

Both web servers are currently using self-signed certs. I can access them internally via https://192.168.1.10:8443. But again, if I try to access https://test01.example.com I get NET::ERR_CERT_COMMON_NAME_INVALID.

Here is my basic config:

server {
    listen          443 ssl http2;
    server_name     example.com;
    root            /usr/share/nginx/html/;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include ssl.conf;
}

server {
    listen          443;
    server_name     test01.example.com;

    location / {
        proxy_pass      $scheme://192.168.1.10:8443;
    }
}

I'll probably have over 20 of these web servers. Do I need to generate a cert for each one?

已采纳解答

原帖链接 · THE JOATMON · CC BY-SA 4.0

I was able to get this to work with a wildcard cert. I generated the cert with certbot using this command:

sudo certbot certonly --agree-tos --email emailaddress --manual --preferred-challenges=dns -d *.example.com --server https://acme-v02.api.letsencrypt.org/directory

I then added ssl_certificate and ssl_certificate_key directives to the server block. I did this with an include so I don't have to duplicate the lines for every subdomain.

wildcard.conf

ssl_certificate       /etc/letsencrypt/live/example.com-wc/fullchain.pem;
ssl_certificate_key   /etc/letsencrypt/live/example.com-wc/privkey.pem;

nginx.conf

 server {
    listen          443 ssl;
    server_name     test01.example.com;
    include         wildcard.conf;

    location / {
            proxy_redirect  off;
            proxy_pass      $scheme://192.168.1.10:8443;
    }

}

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

资料来源与适用范围

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

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

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