Substrate开发之二:配置wss协议、数字证书、nginx
1. 生成证书
1.1 配置文件
在/etc/ssl/下生成一个新配置文件sscert.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| [req] default_bits = 4096 default_md = sha256 distinguished_name = req_distinguished_name x509_extensions = v3_req prompt = no [req_distinguished_name] C = US ST = VA L = SomeCity O = MyCompany OU = MyDivision CN = 127.0.0.1 [v3_req] keyUsage = keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] IP.1 = 127.0.0.1
|
1.2 生成证书
1
| openssl req -nodes -x509 -days 365 -keyout ./substrate/domain.key -out ./substrate/domain.crt -config sscert.cnf
|
1
| openssl x509 -in ./substrate/domain.crt -noout -text
|
2. 配置证书
2.1 nginx配置
打开nginx配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| server { listen 8086 ssl http2;
location / { proxy_pass http://localhost:9944/; proxy_http_version 1.1; proxy_read_timeout 120s; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ssl_certificate /etc/ssl/substrate/domain.crt; ssl_certificate_key /etc/ssl/substrate/domain.key; ssl_session_cache shared:cache_nginx_SSL:1m; ssl_session_timeout 1440m; ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; }
|
重启nginx
2.2 浏览器配置证书
在chrome浏览器设置中搜索证书,管理证书导入domain.crt,大功告成,就可以在https://polkadot.js.org/apps中使用wss连接substrate区块链了。