nginx https双向认证
时间: 2023-12-01 21:42:43 浏览: 50
以下是nginx https双向认证的步骤:
1.生成自签名证书
使用openssl命令生成自签名证书,其中需要设置证书的common name为服务器的域名或IP地址,同时需要设置证书的扩展属性为客户端认证:
```shell
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt -subj "/CN=<server_ip_or_domain>" -addext "subjectAltName = DNS:<server_ip_or_domain>" -addext "extendedKeyUsage = clientAuth"
```
2.配置nginx
在nginx的配置文件中添加以下内容:
```nginx
server {
listen 443 ssl;
server_name <server_ip_or_domain>;
ssl_certificate /path/to/server.crt;
ssl_certificate_key /path/to/server.key;
ssl_client_certificate /path/to/client.crt;
ssl_verify_client on;
location / {
# your server configuration
}
}
```
其中,`ssl_client_certificate`指定客户端证书的路径,`ssl_verify_client on`开启客户端认证。
3.导入客户端证书
将生成的客户端证书分发给客户端,并在客户端的浏览器中导入证书。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)