[Guide] IIS Reverse Proxy Settings #5071

Closed
opened 2025-11-02 06:13:20 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @mahdiit on GitHub (Mar 17, 2020).

  • Gitea version (or commit ref): 1.11
  • Git version: 2.5
  • Operating system: Windows Server 2012 R2
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • [X ] MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • [X ] Not relevant
  • Log gist:

Description

if you need to run gitea with iis, you can not listen to port http and https because iis reserve them
so we need to Setup IIS with URL Rewrite as a reverse proxy
...

1 - Setup an empty website in IIS named it Gitea Proxy
2 - Follow instruction on this tutorial : (I USE ONLY STEP1,STEP2)
https://techcommunity.microsoft.com/t5/iis-support-blog/setup-iis-with-url-rewrite-as-a-reverse-proxy-for-real-world/ba-p/846222#M343

3 - after complete , use Lets Encrypt to secure your site for free
i use https://www.win-acme.com and manual mod
then set validation via Network Path , set Binding Manually in IIS

Originally created by @mahdiit on GitHub (Mar 17, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.11 - Git version: 2.5 - Operating system: Windows Server 2012 R2 - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [X ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [X ] Not relevant - Log gist: ## Description if you need to run gitea with iis, you can not listen to port http and https because iis reserve them so we need to Setup IIS with URL Rewrite as a reverse proxy ... 1 - Setup an empty website in IIS named it Gitea Proxy 2 - Follow instruction on this tutorial : (I USE ONLY STEP1,STEP2) https://techcommunity.microsoft.com/t5/iis-support-blog/setup-iis-with-url-rewrite-as-a-reverse-proxy-for-real-world/ba-p/846222#M343 3 - after complete , use Lets Encrypt to secure your site for free i use https://www.win-acme.com and manual mod then set validation via Network Path , set Binding Manually in IIS
GiteaMirror added the type/docs label 2025-11-02 06:13:20 -06:00
Author
Owner

@mahdiit commented on GitHub (Mar 17, 2020):

app.ini example

[server]
PROTOCOL	= http,https
SSH_DOMAIN       = localhost
DOMAIN           = localhost

sample web.config file in IIS ,
[Loacalhost] and [domain name] must set

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://LOCALHOST:3000/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://LOCALHOST:3000/(.*)" />
                    <action type="Rewrite" value="http{R:1}://DNSNAMEIN-IIS/{R:2}" />
                </rule>
                <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
                    <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="NeedsRestoringAcceptEncoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
        <urlCompression doDynamicCompression="true" />
    </system.webServer>
</configuration>

@mahdiit commented on GitHub (Mar 17, 2020): app.ini example ``` [server] PROTOCOL = http,https SSH_DOMAIN = localhost DOMAIN = localhost ``` sample web.config file in IIS , [Loacalhost] and [domain name] must set ```xml <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="ReverseProxyInboundRule1" stopProcessing="true"> <match url="(.*)" /> <action type="Rewrite" url="http://LOCALHOST:3000/{R:1}" /> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" /> <set name="HTTP_ACCEPT_ENCODING" value="" /> </serverVariables> </rule> </rules> <outboundRules> <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> <match filterByTags="A, Form, Img" pattern="^http(s)?://LOCALHOST:3000/(.*)" /> <action type="Rewrite" value="http{R:1}://DNSNAMEIN-IIS/{R:2}" /> </rule> <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding"> <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="NeedsRestoringAcceptEncoding"> <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" /> </preCondition> </preConditions> </outboundRules> </rewrite> <urlCompression doDynamicCompression="true" /> </system.webServer> </configuration> ```
Author
Owner

@zeripath commented on GitHub (Mar 30, 2020):

Thanks @mahdiit I've taken your comments and added them to the documentation.

@zeripath commented on GitHub (Mar 30, 2020): Thanks @mahdiit I've taken your comments and added them to the documentation.
Author
Owner

@mahdiit commented on GitHub (Aug 4, 2020):

Here is new fixed web.config file

  • Allow view any files in IIS (Removed not allowed files extension)
  • Removed IIS default pages
  • Removed Hidden Segments
<?xml version="1.0" encoding="UTF-8"?>
<!--
SOURCE: 127.0.0.1:3000
PROXY : git.mydomain.com
	-->
<configuration>
	<system.web>
		<httpRuntime relaxedUrlToFileSystemMapping="true" />
	</system.web>
	<system.webServer>
		<defaultDocument>
			<files>				
				<clear />
			</files>
		</defaultDocument>
		<security>
			<requestFiltering>
				<hiddenSegments>
					<clear />
				</hiddenSegments>
				<fileExtensions>
					<clear />
				</fileExtensions>
			</requestFiltering>
		</security>
		<rewrite>
			<rules>
				<rule name="ReverseProxyInboundRule1" stopProcessing="true">
					<match url="(.*)" />
					<action type="Rewrite" url="http://127.0.0.1:3000/{R:1}" />
					<serverVariables>
						<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" />
						<set name="HTTP_ACCEPT_ENCODING" value="" />
					</serverVariables>
				</rule>
			</rules>
			<outboundRules>
				<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
					<match filterByTags="A, Form, Img" pattern="^http(s)?://127.0.0.1:3000/(.*)" />
					<action type="Rewrite" value="http{R:1}://git.mydomain.com/{R:2}" />
				</rule>
				<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
					<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="NeedsRestoringAcceptEncoding">
						<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
					</preCondition>
				</preConditions>
			</outboundRules>
		</rewrite>
		<urlCompression doDynamicCompression="true" />
		<handlers>
			<clear />
			<add name="StaticFile" path="*" verb="*"
				 modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
				 resourceType="Either" requireAccess="Read" />
		</handlers>

		<!-- Map all extensions to the same MIME type, so all files can be
           downloaded. -->
		<staticContent>
			<clear />
			<mimeMap fileExtension="*" mimeType="application/octet-stream" />
		</staticContent>
	</system.webServer>
</configuration>

@mahdiit commented on GitHub (Aug 4, 2020): Here is new fixed web.config file - Allow view any files in IIS (Removed not allowed files extension) - Removed IIS default pages - Removed Hidden Segments ```XML <?xml version="1.0" encoding="UTF-8"?> <!-- SOURCE: 127.0.0.1:3000 PROXY : git.mydomain.com --> <configuration> <system.web> <httpRuntime relaxedUrlToFileSystemMapping="true" /> </system.web> <system.webServer> <defaultDocument> <files> <clear /> </files> </defaultDocument> <security> <requestFiltering> <hiddenSegments> <clear /> </hiddenSegments> <fileExtensions> <clear /> </fileExtensions> </requestFiltering> </security> <rewrite> <rules> <rule name="ReverseProxyInboundRule1" stopProcessing="true"> <match url="(.*)" /> <action type="Rewrite" url="http://127.0.0.1:3000/{R:1}" /> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" /> <set name="HTTP_ACCEPT_ENCODING" value="" /> </serverVariables> </rule> </rules> <outboundRules> <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> <match filterByTags="A, Form, Img" pattern="^http(s)?://127.0.0.1:3000/(.*)" /> <action type="Rewrite" value="http{R:1}://git.mydomain.com/{R:2}" /> </rule> <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding"> <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="NeedsRestoringAcceptEncoding"> <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" /> </preCondition> </preConditions> </outboundRules> </rewrite> <urlCompression doDynamicCompression="true" /> <handlers> <clear /> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" /> </handlers> <!-- Map all extensions to the same MIME type, so all files can be downloaded. --> <staticContent> <clear /> <mimeMap fileExtension="*" mimeType="application/octet-stream" /> </staticContent> </system.webServer> </configuration> ```
Author
Owner

@zeripath commented on GitHub (Aug 4, 2020):

@mahdiit do you fancy making a PR with those?

@zeripath commented on GitHub (Aug 4, 2020): @mahdiit do you fancy making a PR with those?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5071