nginx反向代理多个后端 [英] nginx reverse proxy multiple backends

查看:166
本文介绍了nginx反向代理多个后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:我将有一台运行nginx的前端服务器,以及多台运行apache + passenger并具有不同rails应用程序的后端服务器.我没有尝试进行任何负载平衡.我需要做的是设置nginx以基于URL代理到特定服务器的连接. IE,client.domain.com应指向x.x.x.100:80,client2.domain.com应指向x.x.x.101:80,等等.

Here is my situation: I will have one frontend server running nginx, and multiple backends servers running apache + passenger with different rails applications. I am NOT trying to do any load balancing. What I need to do is setup nginx to proxy connections to specific servers based on the url. IE, client.domain.com should point to x.x.x.100:80, client2.domain.com should point to x.x.x.101:80, etc.

我对nginx不太熟悉,但是找不到适合我情况的在线特定配置.

I am not that familiar with nginx, but I could not find a specific configuration online that fit my situation.

谢谢.

推荐答案

您可以将不同的URL与server {}块进行匹配,然后在每个服务器块内进行反向代理设置.

You can match the different URLs with server {} blocks, then inside each server block, you'd have the reverse proxy settings.

下面是插图;

server { 
  server_name client.domain.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.domain.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 {}块中添加更多的Nginx设置(例如error_pageaccess_log).

Also, you may add further Nginx settings (such as error_page and access_log) as desired in each server {} block.

这篇关于nginx反向代理多个后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆