Reverse proxy + IIS + Docker

2.5k views Asked by At

I have two services running in a swarm (I’ll call them A and B) with replica as 1 which means one container for each service.

Service A has a web application (UI) that calls another web app (api) in service B.

Service A is exposed on 8082 and Service B on 8081.

However I will have to implement some kind off reverse proxy to make this work due to the difference in ports and CORS won’t allow A to call B(even though they are available on same url as they are part of the swarm).

My idea was to have a dummy web api in A along with the existing UI application and add urlReWrite rule to the dummy api so that the request from UI app to dummy web app in Service A will be redirected to the actual one in service B.

For whatever reason this doesn’t work. I just get 404 error. Can someone help me with this?

I’m also posting the dockerfile contents below for Service A which has urlRewrite written into it.

# escape=`

FROM microsoft/aspnet
SHELL ["powershell", "-command"]

# Install urlRewrite 
RUN Invoke-WebRequest http://download.microsoft.com/download/E/9/8/E9849D6A-020E-47E4-9FD0-A023E99B54EB/requestRouter_amd64.msi -UseBasicParsing -OutFile C:/requestrouter.msi; `
  Start-Process msiexec -ArgumentList '/i C:\requestrouter.msi /qn' -Wait; rm C:\requestrouter.msi
  
# Install ARR
RUN Invoke-WebRequest http://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi -UseBasicParsing -OutFile C:/rewrite.msi; `
  Start-Process msiexec -ArgumentList '/i C:\rewrite.msi /qn' -Wait; rm C:\rewrite.msi

# Enable ARR proxy
RUN Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Name 'enabled' -Filter 'system.webServer/proxy' -Value 'True'

# Configure website
EXPOSE 8082  
RUN Set-WebBinding -Name 'Default Web Site' `
    -BindingInformation '*:80:' `
    -PropertyName Port -Value 8082; `
    md C:\inetpub\wwwroot\Application; `    
 md C:\inetpub\wwwroot\webapi; `    
    md c:\transformedsettings; `        
 New-WebApplication -Name 'UIApplication' `
    -Site 'Default Web Site' ` 
    -PhysicalPath 'C:\inetpub\wwwroot\Application' `
    -ApplicationPool '.NET v4.5'; `
 New-WebApplication -Name 'webapi' `
    -Site 'Default Web Site' ` 
    -PhysicalPath 'C:\inetpub\wwwroot\webapi' `
    -ApplicationPool '.NET v4.5';

RUN Add-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\webapi' -filter "system.webServer/rewrite/rules" -name '.' -value @{name='umrp'; patterSyntax='Regular Expressions'; stopProcessing='False'}; `
 Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\webapi' -filter "system.webServer/rewrite/rules/rule[@name='umrp']/match" -name 'url' -value '(.*)'; `
 Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\webapi' -filter "system.webServer/rewrite/rules/rule[@name='umrp']/action" -name 'type' -value 'Rewrite'; `
 Set-WebConfigurationProperty -PSPath 'IIS:\Sites\Default Web Site\webapi' -filter "system.webServer/rewrite/rules/rule[@name='umrp']/action" -name 'url' -value 'http://(manager nodes ip):8081/{R:1}'



# The final instruction copies the site you published earlier into the container.
COPY ./Xpo.LastMile.Portal/bin/Release/PublishOutput C:/inetpub/wwwroot/Application
COPY ./InitializeContainer.ps1 c:/
COPY ./transformedsettings c:/transformedsettings
COPY ./Xpo.LastMile.Portal/angular2 C:/inetpub/wwwroot/Application/angular2
COPY ./Xpo.LastMile.Portal/node_modules C:/inetpub/wwwroot/Application/node_modules
COPY ./Default.html C:/inetpub/wwwroot/webapi

ENTRYPOINT powershell c:\InitializeContainer

0

There are 0 answers