[英]Nginx - Reverse proxy to multiple backends
please before to mark this as duplicated read my own case, it's a bit different from others.请在将其标记为重复之前阅读我自己的案例,它与其他人有点不同。
I'm developing multiple node.js endpoints that I'd like to have under the same domain.我正在开发多个 node.js 端点,我希望在同一个域下拥有这些端点。
These services do respond to something like:这些服务确实对以下内容做出响应:
/user/:user_id/authorization
- base path for the authorization service /user/:user_id/authorization
- 授权服务的基本路径/user/:user_id/log
- base path for the log service /user/:user_id/log
- 日志服务的基本路径And so on.等等。
The first part /user/:user_id/
is the same to all services, it's just a REST way to pass the user id inside the path instead of using the Authentication header.第一部分/user/:user_id/
对所有服务都是一样的,它只是在路径中传递用户 ID 而不是使用 Authentication 标头的 REST 方式。
Is there a way I can reverse-proxy NGINX to these webservices since they are using the same base path?有没有一种方法可以将 NGINX 反向代理到这些 Web 服务,因为它们使用相同的基本路径?
Another question: if NGINX is not used for caching content, may it downgrade node.js performances (for example if its performances are worst than node.js) if it's reverse proxying?另一个问题:如果NGINX不用于缓存内容,如果它是反向代理,它是否会降低node.js的性能(例如如果它的性能比node.js差)?
With nginx you can do whatever routing you want, look here as a start point: http://nginx.org/en/docs/http/request_processing.html and http://nginx.org/r/location使用 nginx 你可以做任何你想做的路由,看这里作为起点: http : //nginx.org/en/docs/http/request_processing.html和http://nginx.org/r/location
Another question: if NGINX is not used for caching content, may it downgrade node.js performances (for example if its performances are worst than node.js) if it's reverse proxying?另一个问题:如果NGINX不用于缓存内容,如果它是反向代理,它是否会降低node.js的性能(例如如果它的性能比node.js差)?
node.js itself or nginx frontend for serving static files? node.js 本身还是用于提供静态文件的 nginx 前端?
Also see: http://www.aosabook.org/en/nginx.html另见: http : //www.aosabook.org/en/nginx.html
If i clearly understand your question you need something like this:如果我清楚地理解你的问题,你需要这样的东西:
server {
listen 80;
server_name default;
root /var/www/;
access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log error;
location / {
if (-f $request_filename) {
access_log off;
expires 30d;
break;
}
error_log off;
error_page 404 = @node;
}
location @node {
if ($uri ~ "/user/(.*)/authorization") { proxy_pass http://127.0.0.1:8080; } #authorization service
if ($uri ~ "/user/(.*)/log") { proxy_pass http://127.0.0.1:8081; } #log service
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
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_ignore_headers X-Accel-Expires Expires Cache-Control;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.