通过 nginxA 如何访问另一个 nginxB 的静态页面

2022-11-16 13:47:00 +08:00
 mytudan

内网环境中 服务器 A 的 nginxA 的端口开了外网,服务器 B 的 nginxB 端口没有外网, 外网能通过 nginxA 的端口访问到 nginxB 中的页面静态资源吗

1370 次点击
所在节点    程序员
8 条回复
eason1874
2022-11-16 13:49:37 +08:00
很简单,就是反代。关键词:nginx proxy_pass
JohnBull
2022-11-16 13:51:04 +08:00
nginxA 的管理员是你的话就能
mytudan
2022-11-16 13:54:01 +08:00
@eason1874 这个应该只能流量转发 比如后端是能转发的 ,但是比如如果现在页面资源是放在 nginxB 中的,直接访问 nginxA 应该是拿不到 nginxB 中的静态资源的吧
@JohnBull 怎么说 把静态资源复制到 nginxA 中吗?
eason1874
2022-11-16 14:00:04 +08:00
@mytudan 可以的,反代跟你静态还是动态没有关系的,只要能访问就能反代

proxy_pass http://服务器 B 的内网 IP:端口;
JohnBull
2022-11-16 14:01:40 +08:00
请定义一下,什么叫“拿到 nginxB 中的静态资源”
Tink
2022-11-16 14:04:20 +08:00
reverse proxy
iPumpkin
2022-11-16 19:56:16 +08:00
nginxB:
server {
listen 3000;
location / {
root /xxx/xxx;
try_files $uri $uri/ /index.html;
}
}

nginxA:
server {
listen 80;
location / {
proxy_pass http://nginxB:3000;
}
}
mytudan
2022-11-17 08:08:39 +08:00
感谢大家 搞定了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/895658

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX