To configure Azure Application Gateway to route traffic based on the URL path correctly, here are some steps and troubleshooting tips:
1. Verify the Configuration
Ensure that the URL path-based routing rules are set up correctly.
- Path-based Routing Rules:
- Go to the Azure Portal > Application Gateway > HTTP Settings.
- Under Routing Rules, ensure that:
- Path-based rules are enabled.
- The correct backend pools are mapped to specific paths.
- Example:
-
/api/*
→ Backend Pool A -
/web/*
→ Backend Pool B
-
- HTTP Settings:
- Verify that each backend pool has the correct HTTP settings configured, including protocols, timeouts, and custom headers if required.
- Ensure that hostnames and paths match what your backend services expect.
2. Check Backend Health
- Go to Backend Health in the Application Gateway settings.
- Verify that all backend targets in your backend pools are healthy.
- If a backend is unhealthy, requests will default to another healthy backend or fail.
3. Set Up Listener and Rules Correctly
- Ensure that the HTTP or HTTPS Listener is properly configured:
- The frontend IP configuration should match the expected incoming requests.
- The Host Header should not be causing mismatches.
- Double-check the rule priority:
- Path-based routing rules are processed sequentially. Ensure there is no conflict or incorrect priority among your rules.
- The default rule should not override path-specific rules.
4. Common Issues and Fixes
Issue: Traffic Always Routes to Default Pool
- Cause: Incorrect or missing path-based routing rules.
- Fix:
- Ensure the
/*
path is not overlapping with specific paths like/api/*
. - Add a fallback path only for traffic that doesn’t match other paths explicitly.
- Ensure the
Issue: Misconfigured Backend Settings
- Cause: Incorrect backend pool configurations.
- Fix:
- Ensure the backend web apps have correct FQDNs or IP addresses.
- If using FQDN, ensure proper DNS resolution and SSL certificates (if HTTPS).
Issue: Backend Authentication Issues
- Cause: Web apps in different resource groups may have different authentication requirements.
- Fix:
- Use Managed Identity or a Service Principal for authentication.
- If the apps require client certificates, ensure they are configured in HTTP settings.
Example Configuration
Path Rules:
-
/api/*
→ Backend Pool: API-WebApp -
/web/*
→ Backend Pool: Frontend-WebApp -
/*
→ Backend Pool: Default-App
Ensure the /*
fallback rule is last in priority.
If these steps do not resolve the issue, provide more details such as:
- Your specific routing rules.
- Access log insights.
- Backend health status.