Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PC 端内网/直连配置教程 #3

Open
F-loat opened this issue Dec 18, 2024 · 0 comments
Open

PC 端内网/直连配置教程 #3

F-loat opened this issue Dec 18, 2024 · 0 comments

Comments

@F-loat
Copy link
Owner

F-loat commented Dec 18, 2024

背景

  1. 小程序通过域名通信时,必须使用 https 协议,且相关域名及端口已在小程序后台配置,若修改需重新发版才能生效
  2. 小程序本身具备局域网通信的能力,但 PC 实测无法正常连通,社区相关问答也没有官方明确回复

解决方案

配置已加白的特定 https 证书的反向代理服务,使用该 https 的域名即可直连访问

配置步骤

  1. 通过本机 host 或路由器 dns 配置将 local.xiaomusic.f-loat.site 解析到 xiaomusic 服务所在的机器 ip 上

    • 配置完成后可通过 ping local.xiaomusic.f-loat.site 来验证是否生效
    • 此时浏览器访问 http://local.xiaomusic.f-loat.site:8090 应该可以打开 xiaomusic 服务的后台页面
  2. 使用 nginx 等服务配置 https 反向代理,监听端口仅 443/8090/9099 可用,配置参考如下

    • 配置完成后可通过 https://local.xiaomusic.f-loat.site 打开 xiaomusic 服务的后台页面
server {
    listen       443 ssl;
    server_name  local.xiaomusic.f-loat.site;

    location / {
        proxy_pass http://IP:PORT; 
    }

    ssl_certificate     /opt/homebrew/etc/nginx/keys/local.xiaomusic.f-loat.site.pem;
    ssl_certificate_key  /opt/homebrew/etc/nginx/keys/local.xiaomusic.f-loat.site.key;
}
  1. 在小程序中将内网服务地址配置为 https://local.xiaomusic.f-loat.site 即可正常使用

备注

  1. 可通过 releases 页面下载最新的证书文件
  2. PC 端在开启网络代理的情况下可能无法联通,可关闭后再次尝试
  3. 公网 ip 可配置公网服务地址直接使用,也可使用类似步骤直连使用
@F-loat F-loat pinned this issue Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant