【发布时间】: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 的理解非常有限,但对我来说,这似乎应该有效,但没有。
感谢您的帮助
【问题讨论】: