1、安装OpenSSL
下载地址:https://slproweb.com/products/Win32OpenSSL.html
2、进入安装目录
3、使用 OpenSSL 生成 SSL Key 和 CSR 文件
openssl req -new -newkey rsa:2048 -sha256 -nodes -out nubomed_local2.csr -keyout nubomed_local2.key -subj "/C=CN/ST=ShenZhen/L=ShenZhen/O=Nubomed Inc./OU=Web Security/CN=nubomed.local2"
下面是上述命令相关字段含义:
- C:Country ,单位所在国家,为两位数的国家缩写,如: CN 就是中国
- ST 字段: State/Province ,单位所在州或省
- L 字段: Locality ,单位所在城市 / 或县区
- O 字段: Organization ,此网站的单位名称;
- OU 字段: Organization Unit,下属部门名称;也常常用于显示其他证书相关信息,如证书类型,证书产品名称或身份验证类型或验证内容等;
- CN 字段: Common Name ,网站的域名
4、生成crt文件
openssl x509 -trustout -req -days 3650 -in nubomed_local2.csr -signkey nubomed_local2.key -out nubomed_local2.crt
5、下载nginx
下载地址:http://nginx.org/en/download.html
6、解压,在根目录下创建ssl文件夹,将上述crt证书和key文件,复制到该目录下
7、修改配置文件nginx.conf
http内添加
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket{
server localhost:8888;
}
server内添加
listen 88;
server_name nubomed.local2;
ssl on;
ssl_certificate C:/Users/Administrator/Desktop/nginx-1.18.0/ssl/nubomed_local2.crt;
ssl_certificate_key C:/Users/Administrator/Desktop/nginx-1.18.0/ssl/nubomed_local2.key;
ssl_session_timeout 30m;
ssl_verify_client off;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
8、测试wss连接方式
wss://nubomed.local2:88/