1、为了能够更方便的访问BLE设备,我决定搭建一个服务器,通过web bluetooth访问本地蓝牙控制ble设备。
2、经过测试发现,如果想通过服务器访问本地的蓝牙,需要使用https协议,而开通https又需要域名,为了省去域名备案的麻烦,需要购买境外的服务器。
3、拿到服务器后,需要将域名解析到服务器的地址。
4、腾讯云服务器通过密码访问
修改/etc/ssh/sshd_config
将PermitRootLogin without-password改成PermitRootLogin yes
添加PasswordAuthentication yes
5、申请免费ssh证书,将证书下载到本地,然后再上传到服务器
6、本文使用Nginx作为反向代理服务器
在/etc/nginx/sites-enabled文件夹下创建文件myproject,输入如下内容:
server {
listen 443 ssl;
server_tokens off;
keepalive_timeout 5;
index index.php index.html;
server_name www.xxx.cn;
ssl_certificate cert/xxx.pem;
ssl_certificate_key cert/xxx.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
#root html;
root /root/working_folder/vue_project/hello-world/dist;
index index.html index.htm;
#proxy_pass http://127.0.0.1:80;
}
}
注意里面的ssl_certificate和ssl_certificate_key,后面跟的地址是证书路径
本例子使用的是vue框架,需要在本地用npm run build编译后,将dist文件夹传输到服务器。
然后在location中配置dist路径。