前言:
今天大家对“nginx配置wss的外网访问”大概比较注意,各位老铁们都想要学习一些“nginx配置wss的外网访问”的相关知识。那么小编也在网络上搜集了一些关于“nginx配置wss的外网访问””的相关资讯,希望大家能喜欢,咱们快快来了解一下吧!硬件需求:需要一台公网服务器需要共有的redis需要两个https的,同时指向服务器服务器安装docker和Docker Compose 和 Caddy进行安装
docker run --rm -it -v$PWD:/output livekit/generate在安装的过程中会让输入服务的域名和turn的域名然后在配置文件进行修改指定的redis进行测试
使用网址 :
livekt服务端部署硬件需求
需要固定ip的服务器一台 用于部署通话服务 安装redis并且修改专门的配置
redis的配置open /usr/local/etc/redis.conf and comment out the line that says bind 127.0.0.1change protected-mode yes to protected-mode no in the same file进行部署通话服务
docker run --rm -v$PWD:/output livekit/generate --local
然后运行服务器 :ws://localhost:7880
修改配置文件找到指定的目录:/root 目录下面的livekit.yaml进行修改配置 redis
redis: # redis is recommended for production deploys address: 172.17.0.1:6379然后运行服务器
docker run --rm -p 7880:7880
-p 7881:7881
-p 7882:7882/udp
-v $PWD/livekit.yaml:/livekit.yaml
livekit/livekit-server
--config /livekit.yaml
--node-ip=127.0.0.1
进行ws转为wss的操作(使用nginx)
必须使用服务器的443端口
然后进行nginx的配置
server { listen 443 ssl; server_name 域名; ssl_certificate 文件的地址; ssl_certificate_key 文件的地址; ssl_session_timeout 5m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; location / { proxy_pass ; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; }
即可完成本地的wss的配置
进行测试是否可用和压力测试
livekit-load-tester --url wss://域名 --api-key 指令key --api-secret 鉴权指令 --room test-room --publishers 1 --subscribers 100 --duration 5m
使用golang进行编写通信服务器
// 创建服务的链接func CreateFactory(https bool) *lksdk.RoomServiceClient { // 定义数据的类型 var roomClient *lksdk.RoomServiceClient if https { host := "; + yml_config.CrateYamlFactory().GetString("Livekit.Url") apiKey := yml_config.CrateYamlFactory().GetString("Livekit.apiKey") apiSecret := yml_config.CrateYamlFactory().GetString("Livekit.apiSecret") roomClient = lksdk.NewRoomServiceClient(host, apiKey, apiSecret) } else { host := yml_config.CrateYamlFactory().GetString("Livekit.Host") apiKey := yml_config.CrateYamlFactory().GetString("Livekit.apiKey") apiSecret := yml_config.CrateYamlFactory().GetString("Livekit.apiSecret") roomClient = lksdk.NewRoomServiceClient(host, apiKey, apiSecret) } return roomClient}// 创建推流的服务器数据func CreateNewEgressClient() *lksdk.EgressClient { host := "; + yml_config.CrateYamlFactory().GetString("Livekit.Url") apiKey := yml_config.CrateYamlFactory().GetString("Livekit.apiKey") apiSecret := yml_config.CrateYamlFactory().GetString("Livekit.apiSecret") egressClient := lksdk.NewEgressClient(host, apiKey, apiSecret) return egressClient}// 创建房间func CreatRoom(roomName string) (*livekit.Room, error) { roomClient := CreateFactory(false) // create a new room room, err := roomClient.CreateRoom(context.Background(), &livekit.CreateRoomRequest{ Name: roomName, }) return room, err}// 获取房间的列表 => 判断房间是否存在func ListRoom(rooName string) (bool, error) { //定义是否存在这个房间 Flag := false roomClient := CreateFactory(false) res, err := roomClient.ListRooms(context.Background(), &livekit.ListRoomsRequest{}) if err != nil { return Flag, err } // 在判断房间是否为空 rooms := res.Rooms if rooms == nil { return Flag, err } // 房间不为空 for _, room := range rooms { if room.Name == rooName { Flag = true } } return Flag, err}//销毁房间终止会议室并导致参与者离开func DestroyRoom(roomId string) { roomClient := CreateFactory(false) roomClient.DeleteRoom(context.Background(), &livekit.DeleteRoomRequest{ Room: roomId, })}//断开某人和会议的链接 =》断开参与者与会议室的连接func DestroyPeople(roomName, identity string) { roomClient := CreateFactory(false) roomClient.RemoveParticipant(context.Background(), &livekit.RoomParticipantIdentity{ Room: roomName, Identity: identity, })}// 列出房间中的参与者func ListRoomPeople(roomName string) *livekit.ListParticipantsResponse { roomClient := CreateFactory(false) res, _ := roomClient.ListParticipants(context.Background(), &livekit.ListParticipantsRequest{ Room: roomName, }) return res}// 创建房间的tokenfunc GetJoinToken(room, identity string) (string, error) { at := auth.NewAccessToken(yml_config.CrateYamlFactory().GetString("Livekit.apiKey"), yml_config.CrateYamlFactory().GetString("Livekit.apiSecret")) grant := &auth.VideoGrant{ RoomJoin: true, Room: room, } at.AddGrant(grant). SetIdentity(identity). SetValidFor(time.Hour) return at.ToJWT()}//后台参数会议 =》可以进行本地的文件在里面进行播放func ParticipationOne(host, apiKey, apiSecret, roomName, identity string) { roomCB := &lksdk.RoomCallback{ ParticipantCallback: lksdk.ParticipantCallback{ OnTrackSubscribed: trackSubscribed, }, } room, err := lksdk.ConnectToRoom(host, lksdk.ConnectInfo{ APIKey: apiKey, APISecret: apiSecret, RoomName: roomName, ParticipantIdentity: identity, }, roomCB) if err != nil { panic(err) } // 操作结束后 room.Disconnect()}// 已按计划订阅func trackSubscribed(track *webrtc.TrackRemote, publication *lksdk.RemoteTrackPublication, rp *lksdk.RemoteParticipant) {}//定义后台接收视频进行存储的操作func PreservationVideo(RoomName string, RTMP string) error { egressClient := CreateNewEgressClient() streamRequest := &livekit.RoomCompositeEgressRequest{ RoomName: RoomName, VideoOnly: true, AudioOnly: true, Layout: "speaker-dark", Output: &livekit.RoomCompositeEgressRequest_Stream{ Stream: &livekit.StreamOutput{ Protocol: livekit.StreamProtocol_RTMP, Urls: []string{RTMP}, }, }, } egress, err := egressClient.StartRoomCompositeEgress(context.Background(), streamRequest) fmt.Printf("错误是====>:%s\n", err) fmt.Printf("信息是====>:%s\n", egress) return err}// 定义房间发送消息func UpdateMetaData(room, identity string, values interface{}) error { roomClient := CreateFactory(true) data, err := json.Marshal(values) participant, err := roomClient.UpdateParticipant(context.Background(), &livekit.UpdateParticipantRequest{ Room: room, Identity: identity, Metadata: string(data), }) fmt.Printf("s信息====>:%s\n", participant) fmt.Printf("错误是====>:%s\n", err) return err}// 删除房间func DeleteRoom(roomName string) (*livekit.DeleteRoomResponse, error) { roomClient := CreateFactory(true) room, err := roomClient.DeleteRoom(context.Background(), &livekit.DeleteRoomRequest{ Room: roomName, }) fmt.Printf("关闭房间错误是====>:%s\n", err) return room, err}使用网址进行测试
定义出口流的操作定义配置文件
在/root/livekit-egress 里面创建文件:cat config.yaml
log_level: debugapi_key: APIRbNLHcS9nF5japi_secret: qwexJ82foYZfXKcGbWphKlibCRyfetsBgMS81gersgSPws_url: ws://172.17.0.1:7880insecure: trueredis: address: 172.17.0.1:6379 db: 4部署出口服务器
docker run --rm
-e EGRESS_CONFIG_FILE=/out/config.yaml
-v ~/livekit-egress:/out
livekit/egress
进行房间流的转推
//定义后台接收视频进行存储的操作func preservationVideo(RoomName string) { ctx := context.Background() egressClient := lksdk.NewEgressClient( "https://域名", "apk", "apiSecret", ) streamRequest := &livekit.RoomCompositeEgressRequest{ RoomName: RoomName, Layout: "speaker-dark", Output: &livekit.RoomCompositeEgressRequest_Stream{ Stream: &livekit.StreamOutput{ Protocol: livekit.StreamProtocol_RTMP, Urls: []string{"rtmp://推流地址:20001/live/489ECAC3"}, }, }, } egress, err := egressClient.StartRoomCompositeEgress(ctx, streamRequest) fmt.Printf("错误是====>:%s\n", err) fmt.Printf("信息是====>:%s\n", egress)}有问题:欢迎关注公众号[shrkPH]
标签: #nginx配置wss的外网访问 #nginx把ws转成wss