简体   繁体   中英

PowerShell script to create a site in IIS with Reverse Proxy to eg. http://localhost:9001

I am trying to automate deployment of our .NET 5 GenericHost services. As they have both a WebAPI and long-running processes, IMHO it makes sense to deploy them as Windows Services and then create a IIS site that acts as reverse proxy. In short:

Browser ---------------------> IIS site -----------------------> WindowsService
         https:/somesite.com             http://localhost:9001 

My "only" problem in this setup is how to create the reverse-proxy IIS site using PowerShell. I have absolute zero experience with this part.

I have figured out, that the IIS Module for PowerShell must be used. But I can't see if it gives access to URL Rewrite 2 , which is the way I know how to do reverse proxy in IIS.

Anybody know about the right documentation for this?

Yes, the PowerShell WebAdministration Module can be used to edit Rewrite configuration

Example to edit a global rule:

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/rewrite/globalRules/rule[@name='Test']/match" -name "url" -value "foobar"

I would use the Configuration Editor in IIS Manager to create the rules and then use the Generate Script feature in the Actions pane to create a PowerShell script which you can then use elsewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM