Skip to content
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

Several 404 errors #4054

Closed
2 of 7 tasks
mcmatze opened this issue Jan 23, 2017 · 7 comments
Closed
2 of 7 tasks

Several 404 errors #4054

mcmatze opened this issue Jan 23, 2017 · 7 comments

Comments

@mcmatze
Copy link

mcmatze commented Jan 23, 2017

Hi,

  • Gogs version (or commit ref): Gogs: Go Git Service 0.9.113.1223
  • Git version: git version 2.7.4
  • Operating system: Ubuntu 16.04.1 LTS
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • SQLite
  • Can you reproduce the bug at https://try.gogs.io:
    • Yes (provide example URL)
    • No
    • Not relevant
    • Site unavailable/too slow

Description

(Please note that I have not much experience with server administration, Plex, nginx, ...)

I have a Server with Plex (nginx enabled) and want to use gogs for some Git repositories. I installed gogs and configured it based on this: https://gogs.io/docs/intro/faqs.html#how-do-i-use-apache-2-with-reverse-proxy%3F .

Here some information:

app.ini

...
[server]
DOMAIN = localhost
HTTP_PORT = 3000
ROOT_URL = http://git.mydomain.com/
DISABLE_SSH = false
SSH_PORT = 22
OFFLINE_MODE = false
...

Additional Apache directives (Plesk)

RewriteEngine On

ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/

I use nginx too. Proxy mode is enabled in the Plesk settings.

I get several 404 errors while browsing through gogs on my server. One example is the "Dashboard" page. The server outputs:

Completed /index.html 404 Not Found in 3.496791ms
[D] Template: status/404

Same happens if I create a repository or click on a repository link.

Can you help me?

@unknwon
Copy link
Member

unknwon commented Jan 24, 2017

Not sure what is the problem exactly, but

  1. DOMAIN = localhost looks wrong to me. You should put your domain here.
  2. Gogs doesn't have index.html page, 404 is the correct response, it is not the URL for dashboard.

@unknwon unknwon closed this as completed Jan 24, 2017
@mcmatze
Copy link
Author

mcmatze commented Jan 24, 2017

Hi,
thanks, now only index.html throws 404. Where do I need to add that file so it shows me that index.html?

@unknwon
Copy link
Member

unknwon commented Jan 24, 2017

There is no index.html in Gogs.

@mcmatze
Copy link
Author

mcmatze commented Jan 24, 2017

But... do I have to create index.html? If I click on dashboard, I see that Gogs is searching for a non-existent index.html. What do I have to do to get that 404 away?

@unknwon
Copy link
Member

unknwon commented Jan 24, 2017

That is your proxy problem which maybe always assume every time you visit / URL redirects to /index.html. I can't help with that..

@soakes
Copy link

soakes commented Mar 11, 2017

Had the same issue as above but thanks to @unknwon hint, I managed to fix the problem very easily with the following extra code in the .htaccess folder as shown below.

DirectoryIndex disabled
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteRule (.*) http://localhost:6000/$1 [P]

Note: I run mine in a subfolder and not subdomain i.e. https://example.com/gogs

To do this, just create a gogs folder (or whatever you want to call it) in your site root, then add the .htaccess file as shown above. Don't forget to update the ROOT_URL in the app.ini file to point to the full URL.

The actual thing which fixes it is, removing Directory Indexing i.e. removing index.html index.php and so forth from the config.

Hope this helps anyone else suffering the same issue.

Sources
Original .htaccess idea/code: #1794
https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex

Martchus pushed a commit to Martchus/gogs that referenced this issue Jun 7, 2018
Martchus pushed a commit to Martchus/gogs that referenced this issue Aug 27, 2018
@JialuZhang
Copy link

@mcmatze

In your configuration,

RewriteEngine On

ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/

the line "RewriteEngine On“ is a silent misconfiguration. This means adding it to your system will not change any system behavior.
"RewriteEngine On" is introduced by Apache to explicitly enable all "RewriteRule" and "RewriteCond".
That is to say, unless you include multiple "RewriteRule" and "RewriteCond" parameters in your configuration, then leaving off "RewriteEngine" is a better choice.

More importantly, the default value of “RewriteEngine" is already an "off", so from a security side, deleting “RewriteEngine On” would be ideal.

The related Apache source code snippet:

run_rewritemap_programs(server_rec *s , apr_pool_t *p){
if (conf->state == ENGINE_DISABLED) { // usage of "RewriteEngine"
  return APR_SUCCESS; // early return
rewritemap_program(...); // usage of "RewriteRule" 
}

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants