
我的 http8008 端口起了一个哪吒面板的服务,目前用 http://域名.com:8008 访问服务正常 我现在想用 https 反代 我希望的结果是当我访问 https://域名.com/nezha/的时候,可以正常的访问哪吒服务 我的 nginx 配置如下
location ^~ /nezha/ { proxy_redirect off; proxy_read_timeout 1200s; proxy_pass http://127.0.0.1:8008/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header Upgrade-Insecure-Requests 1; proxy_set_header X-Forwarded-Proto https; } location ~* /(static)/.*\.(gif|jpg|jpeg|bmp|png|js|css)$ { proxy_pass http://127.0.0.1:8008;#访问路径及端口 } location /ws { proxy_redirect off; proxy_pass http://127.0.0.1:8008; # 转发 proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr:$remote_port; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; # 升级协议头 websocket proxy_set_header Connection upgrade; } 我遇到的问题是,目前首页可以正常使用,但当我点击哪吒面板的其他功能时,页面的链接是 https://域名.com/service
此时 nginx 就代理失败了,页面无法正常访问,请问怎么做才能让我在点击哪吒面板其他功能时,页面的地址是 https://域名.com/nezha/service 呢
1 dethan 2023-01-14 15:02:06 +08:00 没用过哪吒 但是之前遇到过这个问题?类似的问题? 就是服务前端写了绝对路径,导致无法反代,经过查阅资料,我发现了 2 种解决办法: 1. 通过二级域名的方式反代而不是添加自定义前缀: https://域名.com/nezha/ 改成 https://nezha.域名.com 2. 改写前端文件内容: ``` sub_filter 'src="http://www.v2ex.com/assets/' 'src="http://www.v2ex.com/nezha/assets/'; sub_filter 'href="/assets/' 'href="/nezha/assets/'; sub_filter 'url(/assets/' 'url(/nezha/assets/'; sub_filter '/api' '/nezha/api'; sub_filter_types *; sub_filter_once off; ``` |
2 wang794822947 OP @dethan 非常感谢,因为是部署的 docker ,我无法改变他们的前端代码,但是我用第一种方式用了二级域名成功代理了。 |
3 dethan 2023-01-14 15:43:44 +08:00 via Android @wang794822947 第二种方式也是改 nginx 的配置文件,具体用法可以百度下 sub_filter |
5 itechify PRO 这个? https://nezha.wiki/guide/dashboard.html#%E9%85%8D%E7%BD%AE%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86 <a href="https://imgse.com/i/pSQWO0K"><img src="https://s1.ax1x.com/2023/01/15/pSQWO0K.png" alt="pSQWO0K.png" border="0" /></a> |