博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
websocket使用ssl 证书,开启加密服务
阅读量:5088 次
发布时间:2019-06-13

本文共 3196 字,大约阅读时间需要 10 分钟。

参考文章:https://fzambia.gitbooks.io/centrifugal/content/deploy/certificates.html

 

TLS certificates

TLS/SSL layer is very important not only for securing your connections but also to increase a chance to establish Websocket connection. In most situations you will put TLS termination task on your reverse proxy/load balancing software such as Nginx.

There are situations though when you want to serve secure connections by Centrifugo itself.

There are two ways to do this: using TLS certificate cert and key files that you've got from your CA provider or using automatic certificate handling via  provider (only  at this moment).

Using crt and key files

In first way you already have cert and key files. For development you can create self-signed certificate - see  as example.

Then to start Centrifugo use the following command:

./centrifugo --config=config.json --ssl --ssl_key=server.key --ssl_cert=server.crt

Or just use configuration file:

{  ...  "ssl": true,  "ssl_key": "server.key",  "ssl_cert": "server.crt" }

And run:

./centrifugo --config=config.json

Automatic certificates

For automatic certificates from Let's Encrypt add into configuration file:

{  ...  "ssl_autocert": true,  "ssl_autocert_host_whitelist": "www.example.com",  "ssl_autocert_cache_dir": "/tmp/certs",  "ssl_autocert_email": "user@example.com"}

ssl_autocert says Centrifugo that you want automatic certificate handling using ACME provider.

ssl_autocert_host_whitelist is a string with your app domain address. This can be comma-separated list. It's optional but recommended for extra security.

+

 

ssl_autocert_cache_dir is a path to a folder to cache issued certificate files. This is optional but will increase performance.

ssl_autocert_email is optional - it's an email address ACME provider will send notifications about problems with your certificates.

When configured correctly and your domain is valid (localhost will not work) - certificates will be retrieved on first request to Centrifugo.

Also Let's Encrypt certificates will be automatically renewed.

There are tho options (new in v1.6.5) that allow Centrifugo to support TLS client connections from older browsers such as Chrome 49 on Windows XP and IE8 on XP:

  • ssl_autocert_force_rsa - this is a boolean option, by default false. When enabled it forces autocert manager generate certificates with 2048-bit RSA keys.
  • ssl_autocert_server_name - string option, allows to set server name for client handshake hello. This can be useful to deal with old browsers without SNI support - see 

实例:

阿里云下载域名的证书 

上传到服务器  /home/websocket_cert/1522*******822.key  ,   /home/websocket_cert/1522*****4822.pem

 

cat /data/centrifugo/config_ssl.json  "log_level": "debug",  "connection_lifetime": 10,  "admin_password": "admin",  "admin_secret": "admin_secret",  "recover": true,  "admin":true,  "web":true,  "anonymous": true,  "ssl": true,  "ssl_key": "/home/websocket_cert/152******4822.key",  "ssl_cert": "/home/websocket_cert/152******4822.pem"}

 

启动服务:

/data/centrifugo/centrifugo -d -c /data/centrifugo/config_ssl.json -p 9**2  --log_file /data/centrifugo/error_ssl.log --log_level debug --web &

若是阿里云服务器 请在安全组开启 相应端口允许 。 

 

实例访问效果:

 

转载于:https://www.cnblogs.com/weifeng1463/p/8677654.html

你可能感兴趣的文章
一个前端所需具备的PS能力
查看>>
Mac下Jenkins+SVN+Xcode构建持续
查看>>
matplotlib中的颜色及线条控制
查看>>
Linux--逻辑卷管理器
查看>>
SQLServer 在Visual Studio的连接方法
查看>>
CentOS获取公网IP
查看>>
删除文件夹下所有文件
查看>>
巨坑:jqgrid竟然取不到编辑模式下input的值
查看>>
我的Python之路
查看>>
outlook检查姓名快捷键
查看>>
nodejs 教程
查看>>
poj2299 Ultra-QuickSort(线段树求逆序对)
查看>>
归并排序法
查看>>
计算机的核心 --CPU
查看>>
linux下安装tomcat8
查看>>
JZOJ5906【NOIP2018模拟10.15】传送门
查看>>
字符串和十六进制数的相互转换
查看>>
闭包函数与装饰器
查看>>
UIImage图片处理
查看>>
Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)
查看>>