【问题标题】:Basic proxy_pass from nginx from one local ip to another local ip从 nginx 从一个本地 ip 到另一个本地 ip 的基本 proxy_pass
【发布时间】:2021-06-01 09:41:27
【问题描述】:

我是 nginx 的新用户,我正在关注 YouTube 上 Linode 的视频指南(如何设置 NGINX 反向代理)。

我的 nginx 和 apache 服务器都在端口 80 上。我知道这是因为当我在 Firefox 中键入两者的 IP 地址时,它会将我引导到 nginx/apache 欢迎页面。

youtube 视频配置模板如下(其中 server_name 是 linode ip):

server {
  listen 80;
  listen [..]:80;

  server_name 172.105.104.226;
  location / {
      proxy_pass http://localhost:3000/;
  }

在我的 Proxmox 机器上,nginx 服务器位于 192.168.1.241 的 VM 上,而 apache 服务器位于 192.168.1.243 的另一个 VM 上。

查看 nginx 文档,我们发现:

location /some/path/ {
    proxy_pass http://www.example.com/link/;
}

应该代理nginx监听端口接收到的所有流量,并重定向到proxy pass指定的地址。

有了所有这些信息,我的配置文件是这样的:

server {
    listen 80;
    listen [::]:80;
    server_name 192.168.1.241;
    location / {
        proxy_pass http://192.168.1.243;
    }
}

我的理解是这个配置文件应该监听80端口(nginx服务器)上的地址192.168.1.241,并重定向到指定地址192.168.1.243(apache服务器)/

如果我理解正确,Location / 应该接受 nginx 服务器上收到的请求并将其重定向到 apache 服务器。

但是,当我在浏览器中输入 192.168.1.241 时,它不会显示 apache 欢迎消息,而是显示 nginx 欢迎消息。这意味着代理不起作用。

由于我刚刚开始学习,我对 nginx 的理解非常有限,但对我来说,这似乎应该有效,但没有。

感谢您的帮助

【问题讨论】:

    标签: nginx nginx-reverse-proxy


    【解决方案1】:

    事实证明配置是正确的。

    问题是网页被缓存了。通过强制完全刷新,192.168.1.241成功重定向到192.168.1.243。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 2019-11-03
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多