Nginx基于IP的负载均衡

发布于 2024-12-23 16:06:30 字数 84 浏览 1 评论 0原文

我们目前使用 Nginx 服务器进行负载平衡。我们希望我们的办公室 IP 被重定向到特定服务器,而所有其他流量都正常负载平衡。

这可能吗?

We currently use an Nginx server for load balancing. We would like our office IP to be redirected to a specific server, where as all other traffic is load balanced normally.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黒涩兲箜 2024-12-30 16:06:30

您可以使用任何 Web 服务器(Apache、Tomcat、nginx 等)进行简单的重定向。
例如,在 Java 上,您可以使用以下内容创建一个简单的 index.jsp:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Your Company</title>
    <link rel="icon" type="image/png" href="http://www.yourloadbalance.com/favicon.png">
</head>
<body>
<%
response.sendRedirect("www.yourloadbalance.com");
%>
</body>
</html>

这段代码将每个请求重定向到给定的 URL,在您的情况下重定向到负载均衡器。

You can do a simple redirect with any web server (Apache, Tomcat, nginx, etc).
For example, on Java you can create a simple index.jsp with the following:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Your Company</title>
    <link rel="icon" type="image/png" href="http://www.yourloadbalance.com/favicon.png">
</head>
<body>
<%
response.sendRedirect("www.yourloadbalance.com");
%>
</body>
</html>

This piece of code will redirect each request to the given URL, in your case to the load balancer.

じее 2024-12-30 16:06:30

这不是一个有效的配置,但我希望主要思想是清楚的

map $remote_addr $backend {
    default app-servers;
    192.168.1.1 dev-servers; # office IP
}

upstream app-servers { # this is normal upstreams group
    server ...;
    server ...;
}

upstream dev-servers { # this is upstream(s) for Office IP
    server ...; 
}

server {
    listen 80;
    server_name bar.foo.com;

    location / {
        proxy_pass http://$backend;
    }
}

This is not a working config but I hope the main idea is clear

map $remote_addr $backend {
    default app-servers;
    192.168.1.1 dev-servers; # office IP
}

upstream app-servers { # this is normal upstreams group
    server ...;
    server ...;
}

upstream dev-servers { # this is upstream(s) for Office IP
    server ...; 
}

server {
    listen 80;
    server_name bar.foo.com;

    location / {
        proxy_pass http://$backend;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文