【问题标题】:NGINX HTTPS - SSL CertificatesNGINX HTTPS - SSL 证书
【发布时间】:2021-09-24 06:32:23
【问题描述】:

我有三个关于证书的文件:

- example.com.ca-bundle # contains root and intermediate certificates
- example.com.crt # Certificate
- example.com.p7b # only contains certificates and chain certificates

我需要配置 NGINX 以接受 HTTPS,但我感到有点困惑,因为我没有最丰富的 SSL 经验,而且大多数示例似乎都使用证书/密钥对。这种 NGINX 配置是正确的方法吗?

server {
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     /path/to/example.com.crt;
    ssl_certificate_key /path/to/example.com.crt;
    ...
}

【问题讨论】:

  • 您需要拥有私钥。它应该在您创建 CSR 之前创建。如果您没有私钥,则无法创建 HTTPS 服务器。
  • @SteffenUllrich 是正确的。如果您没有私钥,则需要生成一个和另一个 CSR。您的格式在其他方面看起来是正确的,但您需要更改 ssl_certificate_key 以在获得私钥文件而不是证书后使用它。此外,您还需要将 ca-bundle 文件的内容附加到 crt 文件中,以确保您的证书受到浏览器的信任。
  • 谢谢你们!这回答了我的问题。

标签: nginx ssl https


【解决方案1】:

就像其他人在 cmets 中指出的那样,您需要使用 ssl_certificate_key 的私钥。如果它有帮助,下面是使用 Let's Encrypt SSL 证书的 Nginx 配置的摘录。在某些情况下 cert.pem 是不够的,还需要 chain.pem 以实现跨更多浏览器和服务器类型的兼容性。

    # Full chain fullchain.pem is just a concatenation of public key cert.pem and chain.pem. If you are using certbot this will be automatically created.
    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
 
    # Like others pointed out in the comments there should be a private key and not the cert file
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

您可以使用 certbot(Let's Encrypt 的一个工具)来自动生成您的证书。这是Step by Step instructions for automating HTTPS / SSL Certificate setup for your Nginx Hosted Website的链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    相关资源
    最近更新 更多