LouisYLWang / Sync-Sofa

co-play streaming video with remote friends!
https://chrome.google.com/webstore/detail/sync-sofa-online-video-sy/kgpnhgmpijhpkefpddoehhminpfiddmg
MIT License
468 stars 38 forks source link

部署生产服务器是否强制443端口 #46

Closed liqimore closed 3 years ago

liqimore commented 3 years ago

最近尝试部署服务器,版本为v 1.0.6, 使用单个可执行文件在Linux(CentOS 7.9)上执行。 如果设置为生产模式,非443端口启动, 则没有2021/02/07 13:16:12 server is listening at :PORT..., dev模式下启动正常。

我是想以非443端口启动,之后通过nginx反代到443,因为服务器还有其他服务占用443,需要nginx用域名分流,不知这种想法是否可行? 或者只能以开发模式启动,然后通过nginx加入证书,让服务支持443呢? 谢谢

LouisYLWang commented 3 years ago

可以的

onns commented 3 years ago
# sync.conf
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

upstream websocket {
    server 127.0.0.1:85;
}

upstream web{
    server 127.0.0.1:85;
}

server {
    listen 443 ssl; 
    server_name sync-cn.onns.xyz;
    ssl_certificate /etc/nginx/cert/sync.pem;  
    ssl_certificate_key /etc/nginx/cert/sync.key; 
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host  $http_host;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header Connection "";
        proxy_pass http://web;
    }
    location /ws {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

}

内部端口在85,config.json如下:

{
  "addr": ":85",
  "runmode": "dev"
}

详细可以参考Nginx代理websocket,有问题可以在文章下留言,或者该issue

对外必须443,可以用nginx反代,sync-cn.onns.xyz的服务器就是这样的。

liqimore commented 3 years ago

谢谢各位帮助,我按照 @onns 的配置后,发现server在dev模式下,好像是被hardcode进去东西了。如下报错,如有隐私泄漏我马上编辑掉日志。 我明天尝试一下手动编译,可能是打的包有问题。部署好后我会提PR更新到服务器列表中(上海腾讯云和美中两台)。 谢谢

[root@vmi513763 syncsofa]# ./server 
found config file, read parameters from config file...
2021/02/08 00:24:35 server is listening at :30001...
2021/02/08 00:26:03 http: panic serving 127.0.0.1:55674: runtime error: invalid memory address or nil pointer dereference
goroutine 21 [running]:
net/http.(*conn).serve.func1(0xc00014a0a0)
        c:/go/src/net/http/server.go:1772 +0x139
panic(0x700a60, 0x9d6100)
        c:/go/src/runtime/panic.go:973 +0x3e3
github.com/LouisYLWang/Sync-Sofa/server/session.Store.BeginSessions(0xc000062f00, 0x34630b8a000, 0x0, 0xc00014c500, 0x0, 0x0, 0x0, 0x0)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/session/session.go:84 +0x37f
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*Context).SessionSpecificHandler(0xc00000c420, 0x7d5020, 0xc00013a380, 0xc00014c500)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/sessionHandler.go:40 +0xbe
net/http.HandlerFunc.ServeHTTP(0xc000010ce0, 0x7d5020, 0xc00013a380, 0xc00014c500)
        c:/go/src/net/http/server.go:2012 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001b4000, 0x7d5020, 0xc00013a380, 0xc00014c300)
        C:/Users/louis/go/pkg/mod/github.com/gorilla/mux@v1.7.4/mux.go:210 +0xe2
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*CORS).ServeHTTP(0xc000010d90, 0x7d5020, 0xc00013a380, 0xc00014c300)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/cors.go:38 +0x3c7
net/http.serverHandler.ServeHTTP(0xc0001ba000, 0x7d5020, 0xc00013a380, 0xc00014c300)
        c:/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00014a0a0, 0x7d5720, 0xc000134240)
        c:/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
        c:/go/src/net/http/server.go:2933 +0x35c
2021/02/08 00:26:33 http: panic serving 127.0.0.1:55678: runtime error: invalid memory address or nil pointer dereference
goroutine 23 [running]:
net/http.(*conn).serve.func1(0xc00014a140)
        c:/go/src/net/http/server.go:1772 +0x139
panic(0x700a60, 0x9d6100)
        c:/go/src/runtime/panic.go:973 +0x3e3
github.com/LouisYLWang/Sync-Sofa/server/session.Store.BeginSessions(0xc000062f00, 0x34630b8a000, 0x0, 0xc0001d4500, 0x0, 0x0, 0x0, 0x0)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/session/session.go:84 +0x37f
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*Context).SessionSpecificHandler(0xc00000c420, 0x7d5020, 0xc0001ba380, 0xc0001d4500)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/sessionHandler.go:40 +0xbe
net/http.HandlerFunc.ServeHTTP(0xc000010ce0, 0x7d5020, 0xc0001ba380, 0xc0001d4500)
        c:/go/src/net/http/server.go:2012 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001b4000, 0x7d5020, 0xc0001ba380, 0xc0001d4300)
        C:/Users/louis/go/pkg/mod/github.com/gorilla/mux@v1.7.4/mux.go:210 +0xe2
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*CORS).ServeHTTP(0xc000010d90, 0x7d5020, 0xc0001ba380, 0xc0001d4300)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/cors.go:38 +0x3c7
net/http.serverHandler.ServeHTTP(0xc0001ba000, 0x7d5020, 0xc0001ba380, 0xc0001d4300)
        c:/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00014a140, 0x7d5720, 0xc000056640)
        c:/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
        c:/go/src/net/http/server.go:2933 +0x35c
2021/02/08 00:27:01 http: panic serving 127.0.0.1:55680: runtime error: invalid memory address or nil pointer dereference
goroutine 34 [running]:
net/http.(*conn).serve.func1(0xc00009c0a0)
        c:/go/src/net/http/server.go:1772 +0x139
panic(0x700a60, 0x9d6100)
        c:/go/src/runtime/panic.go:973 +0x3e3
github.com/LouisYLWang/Sync-Sofa/server/session.Store.BeginSessions(0xc000062f00, 0x34630b8a000, 0x0, 0xc0000b8300, 0x0, 0x0, 0x0, 0x0)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/session/session.go:84 +0x37f
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*Context).SessionSpecificHandler(0xc00000c420, 0x7d5020, 0xc0000cc000, 0xc0000b8300)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/sessionHandler.go:40 +0xbe
net/http.HandlerFunc.ServeHTTP(0xc000010ce0, 0x7d5020, 0xc0000cc000, 0xc0000b8300)
        c:/go/src/net/http/server.go:2012 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0001b4000, 0x7d5020, 0xc0000cc000, 0xc0000b8000)
        C:/Users/louis/go/pkg/mod/github.com/gorilla/mux@v1.7.4/mux.go:210 +0xe2
github.com/LouisYLWang/Sync-Sofa/server/handlers.(*CORS).ServeHTTP(0xc000010d90, 0x7d5020, 0xc0000cc000, 0xc0000b8000)
        C:/Users/louis/workdir/Sync-Sofa dev/Sync-Sofa/server/handlers/cors.go:38 +0x3c7
net/http.serverHandler.ServeHTTP(0xc0001ba000, 0x7d5020, 0xc0000cc000, 0xc0000b8000)
        c:/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00009c0a0, 0x7d5720, 0xc0000b0000)
        c:/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
        c:/go/src/net/http/server.go:2933 +0x35c
^C
onns commented 3 years ago

server.zip 试试我服务器的版本,直接运行二进制文件

MD5 (server.zip) = 41e143e18405a124479ffe88b6aced24
liqimore commented 3 years ago

感谢帮忙,已经部署好了,我自己测试了一下可以用。使用的包是@onns提供的包。 密苏里州: sync-us-central.pq02.com 北京: sync-bj.204800.xyz 上海: sync-shanghai.204800.xyz

因为不是代码修改,我就不提PR了,需要的话可以直接加到服务器列表里。

onns commented 3 years ago

感谢,等有空我们加到服务器列表里

onns commented 3 years ago

已加!感谢~服务器列表

onns commented 3 years ago

要不要考虑试一下新版本的客户端:https://github.com/LouisYLWang/Sync-Sofa/tree/dev-clean 目前只支持sync-cn.onns.xyz这个服务器

liqimore commented 3 years ago

OK, 我有空升级一下

Sent from my iPhone

On Aug 11, 2021, at 11:16, Onns @.***> wrote:

 要不要考虑试一下新版本的客户端:https://github.com/LouisYLWang/Sync-Sofa/tree/dev-clean 目前只支持sync-cn.onns.xyz这个服务器

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.