[英]Nginx multiple backend one server
I have a server without domain name: 10.23.33.251.我有一个没有域名的服务器:10.23.33.251。 On this server I have two backends (spring boot): 10.23.33.251:8888/apis/a/lot/of/apis 10.23.33.251:9999/apis/a/lot/of/apis在此服务器上,我有两个后端(弹簧启动): 10.23.33.251:8888/apis/a/lot/of/apis 10.23.33.251:9999/apis/a/lot/of/apis
Now I want to configure nginx to handle any request that:现在我想配置 nginx 来处理任何请求:
/be1/employees/1?very_long_params
will be proxy_pass (or proxy_redirect) to 10.23.33.251:8888/apis/employees/1?very_long_params
/be1/employees/1?very_long_params
将是 proxy_pass(或 proxy_redirect)到10.23.33.251:8888/apis/employees/1?very_long_params
/be2/products/10/very/long/params
will be proxy_pass (or proxy_redirect) to 10.23.33.251:9999/apis/products/10/very/long/params
/be2/products/10/very/long/params
将是 proxy_pass(或 proxy_redirect)到10.23.33.251:9999/apis/products/10/very/long/params
But I could not make it work.但我无法让它工作。 Here is my configuration:这是我的配置:
server {
listen 8443;
server_name localhost;
location /be1/* {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8888/apis;
proxy_read_timeout 90;
}
location /be2/* {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:9999/apis;
}
}
Your location
s are defined wrong.您的location
定义错误。 You're trying to use a regular expression but are missing the ~
(or ~*
) operator for that.您正在尝试使用正则表达式,但缺少~
(或~*
)运算符。
It is however not necessary to use regular expressions, you could just use prefix locations:然而,没有必要使用正则表达式,您可以只使用前缀位置:
…
location /be1/ {
…
}
location /be2/ {
…
}
See also: Location Directive Documentation另请参阅: 位置指令文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.