kingmo888 / rustdesk-api-server

基于Django的RustDesk Api&Web Server,除了支持api所有功能,还支持web注册、管理、展示等。已支持到最新1.3.1版本。
979 stars 220 forks source link

SSL Websocket 可以使用nginx反向代理处理 建议不要将ws写死 可以通过反代进行代理或者什么都可以的 #121

Open xiaoyi510 opened 3 months ago

xiaoyi510 commented 3 months ago

SSL Websocket 可以使用nginx反向代理处理 建议不要将ws写死 可以通过反代进行代理或者什么都可以的

image

这里判断当前是https就用wss 否则就用ws

xiaoyi510 commented 3 months ago

21118 什么端口什么的 可以通过路径来转发? 比如 wss://xx/hbbs 转发到内部 127.0.0.1 21118 这样的端口 网页应该有操作空间

kingmo888 commented 3 months ago

欢迎pr啊,我集成进来后没有细研究,主要是对js没能力

xiaoyi510 commented 3 months ago

我也是懒人 哈哈哈

kingmo888 commented 2 months ago

尝试修改了一下,可以试试

kingmo888 commented 2 months ago

21118 什么端口什么的 可以通过路径来转发? 比如 wss://xx/hbbs 转发到内部 127.0.0.1 21118 这样的端口 网页应该有操作空间

这块没搞定。 现在状态是,如果wss链接,就会提示"无法连接注册服务器"了。

xiaoyi510 commented 2 months ago

通过nginx 反向代理 websocket 实现

xiaoyi510 commented 2 months ago
location /xxxxx {
    proxy_pass http://127.0.0.1:21118;
    proxy_set_header Host 127.0.0.1:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    proxy_set_header X-Host $host:$server_port;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 30s;
    proxy_read_timeout 86400s;
    proxy_send_timeout 30s;
    proxy_http_version 1.1;
    // 主要是下面两个是支持websocket的
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
kingmo888 commented 2 months ago
location /xxxxx {
    proxy_pass http://127.0.0.1:21118;
    proxy_set_header Host 127.0.0.1:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    add_header X-Cache $upstream_cache_status;
    proxy_set_header X-Host $host:$server_port;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 30s;
    proxy_read_timeout 86400s;
    proxy_send_timeout 30s;
    proxy_http_version 1.1;
    // 主要是下面两个是支持websocket的
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

技术有限,基于宝塔反代,反复测试了几次,失败了。

能更详细介绍下么

gkaigk commented 2 months ago
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream websocket {
    server 127.0.0.1:21118; 
}
server
    {
        listen 80;
        listen 443;
        server_name XXXX.com;
        index index.html index.htm index.php default.html default.htm default.php;
        location ^~/ {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
            if ($request_method = 'OPTIONS') {
                return 204;
            }
            proxy_pass http://websocket;
            proxy_set_header Host $host; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            }
    }
kingmo888 commented 2 months ago
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream websocket {
    server 127.0.0.1:21118; 
}
server
    {
        listen 80;
        listen 443;
        server_name XXXX.com;
        index index.html index.htm index.php default.html default.htm default.php;
      location ^~/ {
          add_header Access-Control-Allow-Origin *;
          add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
          add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
          if ($request_method = 'OPTIONS') {
              return 204;
          }
          proxy_pass http://websocket;
          proxy_set_header Host $host; 
          proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
          }
    }

当已经存在一个反代(21114)的情况下,这种配置会冲突或者无效。