Skip to content

[1.17.0-RC2] Incorrect ROOT_URL warning when using proxy through apache #20501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gd197 opened this issue Jul 27, 2022 · 9 comments · Fixed by #20502
Closed

[1.17.0-RC2] Incorrect ROOT_URL warning when using proxy through apache #20501

gd197 opened this issue Jul 27, 2022 · 9 comments · Fixed by #20502
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea

Comments

@gd197
Copy link

gd197 commented Jul 27, 2022

Description

Hello,
my configuration :
app.ini
ROOT_URL = https://host.my.company.corp/gitea
httpd gitea.conf

ProxyPass /gitea http://localhost:8888 nocanon
ProxyPassReverse /gitea http://localhost:8888
ProxyRequests Off
AllowEncodedSlashes NoDecode
ProxyPreserveHost On

output logs on starting gitea :
2022/07/27 10:34:14 cmd/web.go:221:listen() [I] [62e0f886-27] AppURL(ROOT_URL): https://host.my.company.corp/gitea/

please note the trailing slash at the end of the ROOT_URL in the log
ROOT_URL warning occurs when trying to access to https://host.my.company.corp/gitea
ROOT_URL warning does not occurs when trying to access to https://host.my.company.corp/gitea/
Did not find a way to force apache to rewrite url before proxying to application listener

Gitea Version

1.17.0-rc2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

RHEL 7.9

How are you running Gitea?

Using gitea build from github release tab

Database

MySQL

@gd197 gd197 added the type/bug label Jul 27, 2022
@gd197 gd197 changed the title [1.17.0-RC2] Incorrect ROOT_URL warning when proxied through apache [1.17.0-RC2] Incorrect ROOT_URL warning when using proxy through apache Jul 27, 2022
@zeripath zeripath added issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea and removed type/bug labels Jul 27, 2022
@zeripath
Copy link
Contributor

Please read the instructions at https://docs.gitea.io/en-us/reverse-proxies/#apache-httpd

Your problem is occurring because of the ProxyPassReverse directive and ProxyPreserveHost.

@wxiaoguang
Copy link
Contributor

I'd like to keep it open and propose a more flexible fix for the URL detection.

@wxiaoguang
Copy link
Contributor

The fix: Some users visit "https://domain/gitea" while appUrl is "https://domain/gitea/", there should be no warning

@gd197
Copy link
Author

gd197 commented Jul 27, 2022

removing ProxyPassReverse directive and ProxyPreserveHost but the issue remains the same.
Tried in app.ini ROOT_URL with and without trailing slash in this configuration does not change the behavior as well

@wxiaoguang
Copy link
Contributor

The PR #20502 will fix the false positive warning.

At the moment, you could bypass it by rewrite (using mod_rewrite) the "/gitea" to "/gitea/" 😂

@gd197
Copy link
Author

gd197 commented Jul 27, 2022

thank you very much for your super fast reply, turning around mod_rewrite since yesterday but still not able to make it works, my guess is that apache is proxying first

@wxiaoguang
Copy link
Contributor

You need something like this to bypass:

    RewriteEngine on
    RewriteRule ^/gitea$ /gitea/ [R=302,L]

@gd197
Copy link
Author

gd197 commented Jul 27, 2022

this is what I'm trying but no luck :(
mod_rewrite is there and enabled
Anyway, your fix will solve that issue I can wait for.
Thanks again for your work and tips

@wxiaoguang
Copy link
Contributor

Now the fix has been released to latest 1.17. You can get it from https://dl.gitea.io/gitea/1.17 or docker gitea:1.17-dev

ps: I have tested the Apache config, it should work (the rewirte need R=302 to do the redirection)

<VirtualHost *:8001>
    RewriteEngine on
    RewriteRule ^/gitea$ /gitea/ [R=302,L]

    DocumentRoot "/var/www/html/8001"
    <Proxy *>
         Order allow,deny
         Allow from all
    </Proxy>
    AllowEncodedSlashes NoDecode
    ProxyPass /gitea http://localhost:8002 nocanon
</VirtualHost>

<VirtualHost *:8002>
    DocumentRoot "/var/www/html/8002"
</VirtualHost>
$ curl -v 127.0.0.1:8001/gitea
> GET /gitea HTTP/1.1
> Host: 127.0.0.1:8001
>
< HTTP/1.1 302 Found
< Location: http://127.0.0.1:8001/gitea/
< Content-Length: 289
< ....
<p>The document has moved <a href="http://127.0.0.1:8001/gitea/">here</a>.</p>
<address>Apache/2.4.54 (Debian) Server at 127.0.0.1 Port 8001</address>

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants