自签证书让Chrome信任的方式(域名情况)
网站是搭建在linux上的,内容大概是一个code-server;我要在windows的chrome中访问,在Linux机器上自签了一个证书,准备让windows中的chrome信任。linux装好openssl。首先买好域名,配置好解析,然后在linux上:
shell
mkdir -p [选一个放证书的目录]
cd [选一个放证书的目录]
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myssl.key -out myssl.crt
在放证书的路径下写一个openssl.cnf如下
text
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = CN
ST = BeiJing(随便写个省份)
L = BeiJing (随便写个城市)
O = BlahBlah (随便写个公司)
OU = BlahBlah (随便写个区域)
CN = website.mydomain.cn (这部分得和域名一样,切记)
[v3_req]
keyUsage = digitalSignature, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = website.mydomain.cn (这部分得和域名一样,切记)
执行
shell
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myssl.key -out myssl.crt -config openssl.cnf
然后配置nginx,这里主要看证书部分,就是server往下的5~6行,其他我也懒得删了
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 443 ssl;
server_name website.mydomain.cn;
ssl_certificate [放证书的路径]/myssl.crt;
ssl_certificate_key [放证书的路径]/myssl.key;
location / {
proxy_pass https://localhost:8080;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
}
重启nginx
然后把myssl.crt下载下来,打开chrome://settings,也就是设置,搜索证书,在安全 那一项里,有一个管理设备证书,然后点进去以后选导入,然后选这个证书导入进来,选择将所有证书放入下列存储的时候有个浏览,受信任的发布者和受信任的根证书颁发机构我都导入了一遍,然后不安全就消失了,websocket也能用了。