gpt4 book ai didi

Nginx 反向代理多个后端

转载 作者:行者123 更新时间:2023-12-03 07:26:30 24 4
gpt4 key购买 nike

这是我的情况:我将有一台运行 Nginx 的前端服务器,以及多台运行 Apache + Passenger 和不同 Rails 应用程序的后端服务器。我不想做任何负载平衡。我需要做的是设置 Nginx 根据 URL 代理到特定服务器的连接。即,client.example.com应该指向x.x.x.100:80 , client2.example.com应该指向x.x.x.101:80

我对 Nginx 不太熟悉,但我在网上找不到适合我情况的具体配置。

最佳答案

您可以将不同的网址与 server {} block 匹配,然后在每个服务器 block 内,您将拥有反向代理设置。

下面是一个插图;

server {
server_name client.example.com;

# app1 reverse proxy follow
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://x.x.x.100:80;

}

server {
server_name client2.example.com;

# app2 reverse proxy settings follow
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://x.x.x.101:80;
}

此外,您还可以根据需要在每个 server {} block 中添加更多 Nginx 设置(例如 error_pageaccess_log)。

关于Nginx 反向代理多个后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13240840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com