# Nginx 如何配置 SSL

**URL:** <https://www.isharkfly.com/t/nginx-ssl/13953>\
**Category:** DevOps\
**Tags:** nginx\
**Created:** [May 7, 2022, 10:31pm UTC](https://www.isharkfly.com/t/nginx-ssl/13953 "2022-05-07T22:31:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [May 7, 2022, 10:31pm UTC](https://www.isharkfly.com/t/nginx-ssl/13953/1 "2022-05-07T22:31:57Z")

</div>

SSL 是目前网站的标配了，如果你还需要使用 Google 或者 Apple 的服务的话，你的网站要求必须使用 SSL。

## Nginx 配置需要的文件

Niginx 配置需要 2 个文件。

- Key 文件
- Crt 文件

Key 文件是你自己生成的，或者使用 SSL 签发网站使用的 key 文件。

Crt 是 CA 机构根据你提供的 Key 文件通过校验后签发给你的，你需要将 Key 和 Crt 文件同时安装到的你的 Nginx 服务器上。

## Nginx 配置路径

如果你为你的站点配置了虚拟服务器的话，那么你需要在你的虚拟服务器上有关 443 端口配置下面的内容：

```auto
server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name src.ossez.com;
        client_max_body_size 500m;

        location / {
                proxy_pass http://localhost:3000;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }

        ssl_certificate /etc/pki/tls/ossez_com/ossez_com.ca.crt;
        ssl_certificate_key /etc/pki/tls/ossez_com/ossez_com.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 10m;
        ssl_ciphers PROFILE=SYSTEM;
        ssl_prefer_server_ciphers on;
}

```

在上面的内容中，我们可以看到了 2 个 文件的安装路径。

当然你也可以配置你自己的路径。

根据上面的说明，key 是你自己生成的文件，crt 是你收到 CA 为你签发的文件。

## 文件内容

如果你收到了 2 个 crt 文件，例如我们使用的签发机构为我们签发了：

ca-bundel 和 crt 文件。

 ![2026-02-14_10-37-51](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/0/b/0b8ed436ba1f998633b1e3d7c1fe50f80d067e5c.png)

如下面图片中显示的内容。

在你将最后的 crt 部署到服务器上之前，你需要将 ca-bundel 和 crt 文件合并成一个 crt 文件。

简单来说就是将 crt 的内容添加到 ca-bundel 文件 **前面** 。

敲黑板： **crt 的内容一定要复制在 ca-bundel 的前面** 。

合并后的 crt 文件看起来和下面一样。

 ![2026-02-14_10-38-26](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/2/8/281e46f82f3250b2da628c1f8ec5838233bd7fa4.jpeg)

是一堆很长的秘钥，直接将这个文件替换掉 Nginx 配置 ssl\_certificate 中指定的文件内容即可。

## 重启 Nginx

在完成上面配置后，重启 Nginx 服务器。

然后访问网站查看你的 SSL 的证书是否被配置正确了。

 ![4ssl-03](https://com-ossez-www-discourse.s3.dualstack.us-east-2.amazonaws.com/discourse-uploads/original/2X/3/31fc45eb7ba7ec15527e98ac2637dbcf46fa5da2.png)

例如我们网站上面的签名信息。

如果你能通过浏览器看到所有的签名，就说明配置成功了。

---

<div class="post-metadata">

**Author:** ![hex](https://www.isharkfly.com/user_avatar/www.isharkfly.com/hex/32/21953_2.png) [@hex](https://www.isharkfly.com/u/hex)\
**Post date:** [February 14, 2026, 3:40pm UTC](https://www.isharkfly.com/t/nginx-ssl/13953/2 "2026-02-14T15:40:59Z")

</div>

> [@honeymoose](#):
>
> **crt 的内容一定要复制在 ca-bundel 的前面**

如果文件内容不在前面的话，重启服务器会得到错误：

```auto
failed (SSL: error:05800074:x509 certificate routines::key values mismatch)

```
