Skip to content

Instantly share code, notes, and snippets.

@duncansmart
Last active April 20, 2021 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncansmart/ab369ff6594322bd03d6fdd289b425e9 to your computer and use it in GitHub Desktop.
Save duncansmart/ab369ff6594322bd03d6fdd289b425e9 to your computer and use it in GitHub Desktop.
IIS reverse proxy to local UniFi Controller
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<httpRuntime requestPathInvalidCharacters="&lt;,>,%,&amp;,\,?" /> <!-- some requests contains mac address thus ":" should be allowed -->
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
<rewrite>
<rules>
<clear />
<rule name="force https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" redirectType="SeeOther" />
</rule>
<rule name="home -> manage" enabled="false" stopProcessing="true">
<match url=".+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="/manage" appendQueryString="false" />
</rule>
<rule name="reverse proxy WebSocket" stopProcessing="true">
<match url="wss/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="client_max_window_bits" />
</serverVariables>
<action type="Rewrite" url="{C:1}://localhost:8443/wss/{R:1}" />
</rule>
<rule name="reverse proxy" enabled="true" patternSyntax="Wildcard" stopProcessing="false">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_HOST" value="localhost:8443" />
<set name="HTTP_REFERER" value="https://localhost:8443" />
<set name="HTTP_ORIGIN" value="https://localhost:8443" />
<!--set name="HTTP_X_FORWARDED_HOST" value="unifi.lexonis.com" />
<set name="HTTP_X_FORWARDED_PROTO" value="https" />
<set name="HTTP_X_FORWARDED_PORT" value="443" /-->
</serverVariables>
<action type="Rewrite" url="https://localhost:8443/{R:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<caching enabled="false" enableKernelCache="false" />
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment