基于ARR实现双服务器IIS多应用多端口负载均衡配置咨询
Hey there! Let's walk through setting up your two IIS apps with ARR load balancing step by step—this is totally manageable once we break it down into clear tasks:
First, make sure both servers (let's call them Server X and Server Y for clarity) are running a supported Windows Server version (2019 or 2022 works best). Then:
- Install IIS on each server: Open
Server Manager, go toAdd Roles and Features, check Web Server (IIS) in the roles list, and follow the wizard. Don't forget to add any app-specific features (like ASP.NET Core if your apps use .NET Core) during setup.
On each application server, set up the two apps via IIS Manager:
- Right-click Sites > Add Website
- For app1:
- Name it
app1 - Point the physical path to your app1's code directory
- Set the port to
789, leave the hostname blank (we'll use port numbers to distinguish apps), then click OK
- Name it
- Repeat the process for app2, setting the port to
790
- For app1:
- Test each app locally first: On the server, open a browser and go to
http://localhost:789andhttp://localhost:790to confirm they load. Then test from another machine usinghttp://[Server-IP]:789to ensure network connectivity.
You'll need a dedicated load balancer (LB) server (or you can use one of your app servers for testing, but a separate server is better for production). First install IIS on the LB, then:
- Open IIS Manager, select the server name, and look for Web Platform Installer in the IIS section (if you don't have it, install it first via Windows features or official Microsoft tooling).
- Search for
Application Request Routing 3.0in the Web Platform Installer, select it, and click Install. Follow the prompts to finish setup. - Restart IIS Manager, and you'll see a new Server Farms node—this is where we'll configure load balancing.
We'll create two separate server farms: one for app1 (forwarding to port 789) and one for app2 (forwarding to port 790).
Set Up the app1 Server Farm
- Right-click Server Farms > Create Server Farm
- Name it
App1-Servers, check Enable proxy, then click Next - Add the IP addresses (or hostnames, if DNS resolves them) of your two app servers, then click Next > Finish
- Name it
- Now configure the farm to route to port 789:
- Select
App1-Servers, go to the Proxy tab - Under Forwarding, set the Forward URL to
http://{SERVER_ADDRESS}:789(the{SERVER_ADDRESS}variable will automatically use the backend server IPs you added)
- Select
- Configure load balancing behavior:
- Go to the Load Balance tab, pick an algorithm (Round Robin is default and works for most cases; Least Connections is better if your apps have long-running requests)
- Set up health checks (critical for failover):
- Go to the Health Test tab, set the Test URL to
/(or a specific health check endpoint your app has) - Adjust the test interval and timeout to match your app's needs—this ensures ARR will stop sending traffic to a server if it's unresponsive
- Go to the Health Test tab, set the Test URL to
Repeat for the app2 Server Farm
- Follow the exact same steps as above, but name the farm
App2-Servers - In the Proxy tab, set the Forward URL to
http://{SERVER_ADDRESS}:790 - Configure the same load balancing algorithm and health checks as app1
Link the LB to the Server Farms
Now we need to set up the LB to listen for incoming requests and route them to the right farm:
- For app1:
- On the LB's IIS Manager, right-click Sites > Add Website
- Name it
App1-LB, set the port to8080(you can use any port you prefer), and pick an empty folder for the physical path (we're just forwarding traffic, not hosting files here) - Select the
App1-LBsite, go to URL Rewrite > Add Rule(s) > Reverse Proxy - Uncheck Enable SSL Offloading (skip this if you're using HTTPS), then click OK
- Edit the new rewrite rule: Go to the Action tab, set Action type to
Route to Server Farm, and selectApp1-Serversfrom the dropdown. Save the rule.
- For app2:
- Add another website named
App2-LB, set the port to8081 - Repeat the reverse proxy setup, routing to the
App2-Serversfarm
- Add another website named
Now it's time to verify everything works:
- From a client machine, visit
http://[LB-Server-IP]:8080and refresh multiple times. To confirm traffic is being distributed, you can add a simple snippet to app1 that displays the server's IP address, or check the IIS logs on both backend servers. - Do the same for app2 at
http://[LB-Server-IP]:8081 - Test failover: Shut down app1 on one backend server, then keep refreshing the LB's app1 URL. ARR should automatically route all traffic to the working server.
- HTTPS Support: Install an SSL certificate on the LB, enable SSL Offloading, and update the rewrite rules to use HTTPS. This lets the LB handle encryption, so your backend servers don't have to.
- Session Affinity: If your app requires users to stay on the same server (for session data), go to the server farm's Session Affinity tab and select either
Client IPorCookiebased on your needs. - Timeout Tuning: Adjust connection and response timeouts in the server farm's Proxy tab to match how long your app takes to respond.
内容的提问来源于stack exchange,提问作者bharat Garg

