如何根据Nginx中的请求URL重定向到特定的上游服务器?

前端之家收集整理的这篇文章主要介绍了如何根据Nginx中的请求URL重定向到特定的上游服务器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Nginx作为我的5个应用服务器的负载均衡器.

我想根据请求URL重定向到特定服务器,例如:

@H_301_7@acme.com/category/* => Server #1 acme.com/admin/* => Server #2 api.acme.com => Server #3 Fallback for any other URL => Server #4,#5

我的配置如下:

@H_301_7@upstream backend { least_conn; server 10.128.1.1; server 10.128.1.2; server 10.128.1.3; server 10.128.1.4; server 10.128.1.5; } server { listen 80; server_name _; location / { proxy_set_header Host $host; proxy_pass http://backend; } }

我不知道怎么做,因为我对Nginx不太熟悉 – 任何人都有一些线索?

阅读the documentation,eveything在其中得到了很好的解释.特别是beginner’s guide解释了基础知识.你会最终得到:

@H_301_7@upstream backend { least_conn; server 10.128.1.4; server 10.128.1.5; } server { server_name _; location / { proxy_set_header Host $host; proxy_pass http://backend; } } server { server_name acme.com; location /admin/ { proxy_set_header Host $host; proxy_pass http://10.128.1.2; } location /category/ { proxy_set_header Host $host; proxy_pass http://10.128.1.1; } location / { proxy_set_header Host $host; proxy_pass http://backend; } } server { server_name api.acme.com; location / { proxy_set_header Host $host; proxy_pass http://10.128.1.3; } }

猜你在找的Nginx相关文章