Registrati Accedi
n/program · 2025-03-03 · 461 visualizzazioni
u/StrMembro onorarioMaestro
n/programu/Str Socio onorario · 2025-03-03

给我74了,有人知道这个bug怎么整吗

首先我在 http://sd.xh.sd:8080 开了个服务(但是没有https,你打开会提示不支持serviceWork)
然后用host分留,fox.xh.sd 和 sd.xh.sd 都是绑定到一个服务器上的,服务器通过判断host转发请求
目前的情况是 fox.xh.sd 是支持https了,但是无法加载配置sw的页面(直接秒bad gateway,非常不正常)

sd.xh.sd 的后端有个这样子写的:

```
const proxyMiddleware = createProxyMiddleware({
target: 'http://localhost:8080',
changeOrigin: true,
});

app.use(
'/',
(req, res, next) => {
const host = req.headers.host?.split(':')[0];
if (host === 'fox.xh.sd') {
proxyMiddleware(req, res, next);
} else {
next();
}
}
);
```
理论上来说肯定是正常的,用 http://sd.xh.sd:8080 + 手动忽略 sw 错误,可以发现比 https://fox.xh.sd/ 加载出来了 sw 配置页面(你打开对比看不到很正常,加载时就有sw验证),然后因为sw无法使用转到错误页



目前有没有人能试试用nodejs的express写一个反代,把这个站 http://sd.xh.sd:8080 反代到https上,感激不尽

0
4
Accedi per partecipare alla discussione.

4 risposte

Ordinamento
  1. Hoog2025 💬 Diamante 2025-03-03

    我也青铜了,也没给我升

    0
  2. dfjk Platino 2025-03-03

    为什么不用 Nginx 配置反代呢?

    0
  3. James 💯 Leggenda MANAGER 2025-03-03

    sw在后台是哪个端口呢?

    0
  4. dfjk Platino 2025-03-03

    不是很了解 Node.js,但我看了一眼文档,好几个相关的选项你都没写,不知道是不是必须的。

    ```
    option.ssl: object to be passed to https.createServer()
    option.ws: true/false: if you want to proxy websockets
    option.secure: true/false, if you want to verify the SSL Certs
    option.protocolRewrite: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
    ```
    
    0