Cấu hình Jenkins Reverse Proxy cho IIS

Bước 1: Cài đặt IIS, thêm sites mới cho Jenkins.

Bước 2: Cài đặt URL Rewrite và IIS ARR

Bước 3: Chọn Application Request Routing Cache -> Server Proxy Settings

Bước 4: Cấu hình IIS site jenkins theo domain

Bước 5: Thêm file web.config vào folder chứa jenkins

Bước 6: Copy nội dung web.config dưới đây vào file của bạn, thay nội dung domain thành của bạn

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:80/(.*)" />
<action type="Rewrite" value="http{R:1}://jenkins.tuanitpro.com/{R:2}" />
</rule>
<rule name="RestorageAccessEncoding" preCondition="RestorageAccessEncoding" enabled="true">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="RestorageAccessEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:80/{R:1}" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCONDING}" />
<set name="HTTP_ACCEPT_ENCODING" />

<set name="HTTP_FORWARDED" value="for={REMOTE_ADDR};by={LOCAL_ADDR};host=&quot;{HTTP_HOST}&quot;;proto=&quot;https&quot;" />
</serverVariables>

</rule>
</rules>
</rewrite>
<urlCompression doStaticCompression="false" />
</system.webServer>
</configuration>

Nguồn tham khảo:

– https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+behind+IIS

– https://rlevchenko.com/2018/12/27/using-iis-as-a-reverse-proxy-for-jenkins/