Route Web Server Request to App server through proxy
Route Web Server Request to App server through proxy
Step 1 – Download and install required dependency on IIS Server
Application Request Routing Module
Download URL: - https://www.microsoft.com/en-us/download/details.aspx?id=47333
URL Rewrite Module
Download URL: - https://www.microsoft.com/en-in/download/details.aspx?id=7435
Step 2 – Configure ARR as a Forward Proxy
To enable ARR as a proxy, and to create a URL Rewrite rule to enable ARR as a forward proxy, proceed as follows:
1. Open Internet Information Services (IIS) Manager.
2. In the Connections pane, select the server.
3. In the server pane, double-click Application Request Routing Cache
4. In the Actions pane, click Server Proxy Settings.
5. On the Application Request Routing page, select Enable proxy.
6. In the Actions pane, click Apply. This enables ARR as a proxy at the server level.
7. To start the process of turning ARR into a forward proxy, click on the server node in the Connections pane
8. In the server pane, double-click URL Rewrite.
9. In the Actions pane, click Add Rule(s).
10. In the Add Rule dialog box, double-click Blank Rule.
11. In the Edit Inbound Rule dialog box
1. Name : - Rule Name
2. Pattern: - Will base on how you’re calling API from environment.ts file.
Example: - http://www.webserver.com/api/
Pattern: - ^api/(.*)
3. Test Pattern – You can test your pattern by clicking on button test pattern and out same web request.
4. Action : - Rewrite
5. Rewrite URL: Your app server URL
Example 1: -http://www.apiserver.com/
Example 2: -http://www.apiserver.com/api/ - written api after domain name because all API request are be starting from /api
12. In the Actions pane, click Apply.
13. Restart iis server
Example: -
Angular prod-enviorment.ts
apiUrl:- http://www.webserver.com/api/
Below is my web.config file, when we will add URL rewrite rule in URL Rewrite Module then it will automatic reflect in web.config.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^api/(.*)" />
<action type="Rewrite" url="http://www.appserver.com/api/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Reference Links: -
1. https://docs.microsoft.com/en-us/iis/extensions/configuring-application-request-routing-arr/creating-a-forward-proxy-using-application-request-routing
2. https://www.stefanoscerra.it/iis-rewrite-rules-configuration-angular-web-config/
3. https://tecadmin.net/enable-url-rewrite-iis/
4. https://port135.com/2018/10/18/how-to-check-if-arr-extension-is-installed-in-iis/
Comments
Post a Comment