gitea work incorrectly with IIS and sub-path's #8470

Closed
opened 2025-11-02 08:07:27 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @PerlAmutor on GitHub (Feb 2, 2022).

Gitea Version

1.15.6

Git Version

2.35

Operating System

Windows

How are you running Gitea?

I create service with "sc" command on gitea-1.15.6-windows-4.0-amd64.exe (renamed to gitea.exe)
Setting IIS for reverse-proxy on same machine

Database

SQLite

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Description

I have a few problems with gitea.

  1. On our server apply domain policy, so all JavaScripts are disabled (I don't have permissions for enable it)
  2. So I try setting IIS for reverse-proxy in make all settings with browser on remote machine
  3. All sites on IIS server accessed via sub-path's like:
Default web site:
		|
		- Site1
		|
		- Site2
		|
		- Site3
		|
		- gitea
		
http://server/site1
http://server/site2
http://server/site3
http://server/gitea
  1. When I open site "http://server/gitea" on remote machine I see error: err_too_many_redirects (310)
    It happens because gitea still not installed. So I installed gitea on local machine and copy config file app.ini on server, changed with notepad and it opened via browser after restart gitea.
  2. But a few important links, like Register, Home, Sign-in still have url like: http://server/home (not a http://server/gitea/home) and I can't continue work with that, because all clicks on it transfer me to error page 404.
  3. Another problem with service. Created service always have status "Starting...", I can only kill process from task-manager, "sc stop" etc doesn't work.

Screenshots

No response

Originally created by @PerlAmutor on GitHub (Feb 2, 2022). ### Gitea Version 1.15.6 ### Git Version 2.35 ### Operating System Windows ### How are you running Gitea? I create service with "sc" command on gitea-1.15.6-windows-4.0-amd64.exe (renamed to gitea.exe) Setting IIS for reverse-proxy on same machine ### Database SQLite ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Description I have a few problems with gitea. 1. On our server apply domain policy, so all JavaScripts are disabled (I don't have permissions for enable it) 2. So I try setting IIS for reverse-proxy in make all settings with browser on remote machine 3. All sites on IIS server accessed via sub-path's like: ``` Default web site: | - Site1 | - Site2 | - Site3 | - gitea http://server/site1 http://server/site2 http://server/site3 http://server/gitea ``` 4. When I open site "http://server/gitea" on remote machine I see error: err_too_many_redirects (310) It happens because gitea still not installed. So I installed gitea on local machine and copy config file app.ini on server, changed with notepad and it opened via browser after restart gitea. 5. But a few important links, like Register, Home, Sign-in still have url like: http://server/home (not a http://server/gitea/home) and I can't continue work with that, because all clicks on it transfer me to error page 404. 6. Another problem with service. Created service always have status "Starting...", I can only kill process from task-manager, "sc stop" etc doesn't work. ### Screenshots _No response_
GiteaMirror added the issue/needs-feedback label 2025-11-02 08:07:27 -06:00
Author
Owner

@techknowlogick commented on GitHub (Feb 2, 2022):

Please attempt with latest stable 1.16.0, as the issue you are facing may be resolved.

@techknowlogick commented on GitHub (Feb 2, 2022): Please attempt with latest stable 1.16.0, as the issue you are facing may be resolved.
Author
Owner

@wxiaoguang commented on GitHub (Feb 3, 2022):

Check your ROOT_URL in app.ini, make sure it is correct

@wxiaoguang commented on GitHub (Feb 3, 2022): Check your `ROOT_URL` in `app.ini`, make sure it is correct
Author
Owner

@PerlAmutor commented on GitHub (Feb 4, 2022):

Problem still exists on 1.16.0

image

As you can see, not all links have sub-path.

This my IIS web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <httpRuntime requestPathInvalidCharacters="" />
    </system.web>
    <system.webServer>
        <security>
          <requestFiltering>
            <hiddenSegments>
              <clear />
            </hiddenSegments>
            <denyUrlSequences>
              <clear />
            </denyUrlSequences>
            <fileExtensions allowUnlisted="true">
              <clear />
            </fileExtensions>
          </requestFiltering>
        </security>
        <rewrite>
            <rules useOriginalURLEncoding="false">
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://127.0.0.1:3000/{R:1}" appendQueryString="true" />
                    <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">
                    <!-- set the pattern correctly here - if you only want to accept http or https -->
                    <!-- change the pattern and the action value as appropriate -->
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://127.0.0.1:3000/(.*)" />
                    <action type="Rewrite" value="http{R:1}://server1/{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>
        <defaultDocument enabled="false" />
    </system.webServer>
</configuration>

And app.ini:

APP_NAME = Gitea: Git with a cup of tea
RUN_USER = 107076W1$
RUN_MODE = prod

[server]
PROTOCOL = http
DOMAIN = server1
ROOT_URL = http://server1/gitea
STATIC_URL_PREFIX = /gitea
HTTP_ADDR = 0.0.0.0
HTTP_PORT = 3000
LANDING_PAGE = home

[security]
INTERNAL_TOKEN     = HIDED
INSTALL_LOCK       = true
SECRET_KEY         = HIDED
PASSWORD_HASH_ALGO = pbkdf2

[database]
DB_TYPE  = sqlite3
HOST     = 127.0.0.1:3306
NAME     = gitea
USER     = gitea
PASSWD   = 
SCHEMA   = 
SSL_MODE = disable
CHARSET  = utf8
PATH     = C:/gitea/data/gitea.db
LOG_SQL  = false

[repository]
ROOT = C:/gitea/data/gitea-repositories

[server]
SSH_DOMAIN       = localhost
DOMAIN           = localhost
HTTP_PORT        = 3000
ROOT_URL         = http://localhost:3000/
DISABLE_SSH      = false
SSH_PORT         = 22
LFS_START_SERVER = true
LFS_CONTENT_PATH = C:/gitea/data/lfs
LFS_JWT_SECRET   = HIDED
OFFLINE_MODE     = false

[mailer]
ENABLED = false

[service]
REGISTER_EMAIL_CONFIRM            = false
ENABLE_NOTIFY_MAIL                = false
DISABLE_REGISTRATION              = false
ALLOW_ONLY_EXTERNAL_REGISTRATION  = false
ENABLE_CAPTCHA                    = false
REQUIRE_SIGNIN_VIEW               = false
DEFAULT_KEEP_EMAIL_PRIVATE        = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING       = true
NO_REPLY_ADDRESS                  = noreply.localhost

[picture]
DISABLE_GRAVATAR        = true
ENABLE_FEDERATED_AVATAR = false

[openid]
ENABLE_OPENID_SIGNIN = true
ENABLE_OPENID_SIGNUP = true

[session]
PROVIDER = file

[log]
MODE      = console
LEVEL     = info
ROOT_PATH = C:/gitea/log
ROUTER    = console


@PerlAmutor commented on GitHub (Feb 4, 2022): Problem still exists on 1.16.0 ![image](https://user-images.githubusercontent.com/87958986/152466354-6ca2ef7d-f126-4150-b49a-4e3556c7a102.png) As you can see, not all links have sub-path. This my IIS web.config: ``` <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.web> <httpRuntime requestPathInvalidCharacters="" /> </system.web> <system.webServer> <security> <requestFiltering> <hiddenSegments> <clear /> </hiddenSegments> <denyUrlSequences> <clear /> </denyUrlSequences> <fileExtensions allowUnlisted="true"> <clear /> </fileExtensions> </requestFiltering> </security> <rewrite> <rules useOriginalURLEncoding="false"> <rule name="ReverseProxyInboundRule1" stopProcessing="true"> <match url="(.*)" /> <action type="Rewrite" url="http://127.0.0.1:3000/{R:1}" appendQueryString="true" /> <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"> <!-- set the pattern correctly here - if you only want to accept http or https --> <!-- change the pattern and the action value as appropriate --> <match filterByTags="A, Form, Img" pattern="^http(s)?://127.0.0.1:3000/(.*)" /> <action type="Rewrite" value="http{R:1}://server1/{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> <defaultDocument enabled="false" /> </system.webServer> </configuration> ``` And app.ini: ``` APP_NAME = Gitea: Git with a cup of tea RUN_USER = 107076W1$ RUN_MODE = prod [server] PROTOCOL = http DOMAIN = server1 ROOT_URL = http://server1/gitea STATIC_URL_PREFIX = /gitea HTTP_ADDR = 0.0.0.0 HTTP_PORT = 3000 LANDING_PAGE = home [security] INTERNAL_TOKEN = HIDED INSTALL_LOCK = true SECRET_KEY = HIDED PASSWORD_HASH_ALGO = pbkdf2 [database] DB_TYPE = sqlite3 HOST = 127.0.0.1:3306 NAME = gitea USER = gitea PASSWD = SCHEMA = SSL_MODE = disable CHARSET = utf8 PATH = C:/gitea/data/gitea.db LOG_SQL = false [repository] ROOT = C:/gitea/data/gitea-repositories [server] SSH_DOMAIN = localhost DOMAIN = localhost HTTP_PORT = 3000 ROOT_URL = http://localhost:3000/ DISABLE_SSH = false SSH_PORT = 22 LFS_START_SERVER = true LFS_CONTENT_PATH = C:/gitea/data/lfs LFS_JWT_SECRET = HIDED OFFLINE_MODE = false [mailer] ENABLED = false [service] REGISTER_EMAIL_CONFIRM = false ENABLE_NOTIFY_MAIL = false DISABLE_REGISTRATION = false ALLOW_ONLY_EXTERNAL_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false DEFAULT_ALLOW_CREATE_ORGANIZATION = true DEFAULT_ENABLE_TIMETRACKING = true NO_REPLY_ADDRESS = noreply.localhost [picture] DISABLE_GRAVATAR = true ENABLE_FEDERATED_AVATAR = false [openid] ENABLE_OPENID_SIGNIN = true ENABLE_OPENID_SIGNUP = true [session] PROVIDER = file [log] MODE = console LEVEL = info ROOT_PATH = C:/gitea/log ROUTER = console ```
Author
Owner

@lunny commented on GitHub (Feb 4, 2022):

You have two [server] sections.

@lunny commented on GitHub (Feb 4, 2022): You have two `[server]` sections.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8470