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

ROOT_URL not set after many install problems, errors, 404s #19972

Closed
TokisanGames opened this issue Jun 15, 2022 · 7 comments
Closed

ROOT_URL not set after many install problems, errors, 404s #19972

TokisanGames opened this issue Jun 15, 2022 · 7 comments
Labels

Comments

@TokisanGames
Copy link

TokisanGames commented Jun 15, 2022

Description

The goal: Set up gitea in a subdirectory on my VPS under https, eg https://example.com/git/ . No docker.

I had a ton of issues setting up a reverse proxy under SSL and a subdirectory. I read through countless issues, but couldn't find a complete working example that worked for me. Also the reverse proxy guide did not work for me. I either got broken images and 404 errors. I think I have it mostly working now, but I have one persistent error on screen, and what is probably a small bug appearing in my logs.

Current issues

I've made an admin, a user, an organization, and an empty repo. I can browse around the system. It seems like things work so far.

  1. I can't get rid of this error message. It appears at the top of every screen in red, constantly. ROOT_URL is set.
Your ROOT_URL in app.ini is undefined but you are visiting https://example.com/git/
You should set ROOT_URL correctly, otherwise the web may not work correctly.
  1. I get errors like this in my logs and the 404s appear in my browser console. :
2022/06/14 20:57:49 ...s/context/context.go:314:PlainTextBytes() [E] PlainTextBytes: Not found.
2022/06/14 20:57:49 Completed GET /repo/search?count_only=1&uid=2&team_id=0&q=&page=1&mode= 404 Not Found in 2.741671ms
2022/06/14 20:57:49 Completed GET /repo/search?sort=updated&order=desc&uid=2&team_id=0&q=&page=1&limit=15&mode=&archived=false 404 Not Found in 2.64007ms

These appear on https://example.com/git/ when logged in and looking at my dashboard. Likely because there are no general repos, only one within an organization and rather than checking for that, it is queried anyway.

Set up

I downloaded a prebuilt package that did not come with static assets, so I built those from the source repo but could not figure out where to put them so they could be served by the embedded server. I also couldn't enable enough logging to see the complaints on individual files. Enabling access logs and trace level logs in app.ini didn't actually give me per asset logs and errors.

Nginx config
I placed the assets in /var/lib/gitea/public, so css, img, js are directly under that folder.
server {
    server_name example.com www.example.com;
    listen 443 default_server ssl http2;
    listen [::]:443 default_server ssl http2;

    ssl_certificate /etc/ssl/local/example.com-bundle.crt;
    ssl_trusted_certificate /etc/ssl/local/example.com-bundle.crt;
    ssl_certificate_key /etc/ssl/local/example.com.key;
    include snippets/ssl-intermediate.conf;

    root /var/www/example/www;
    index index.php;
    access_log /var/www/example/logs/access.log;
    error_log /var/www/example/logs/error.log ;

    include snippets/restrictions.conf;

    # Gitea
    location ^~ /git/assets/ {
        root        /var/lib/gitea/public;
        rewrite     ^/git/assets/(.*)$ /$1 break;
        access_log  /var/lib/gitea/log/nginx_access.log;
        error_log   /var/lib/gitea/log/nginx_error.log;
        try_files   $uri =404;
    }

    location /git/ {
        access_log  /var/lib/gitea/log/nginx_access.log;
        error_log   /var/lib/gitea/log/nginx_error.log;
        rewrite     ^/git/(.*)$ /$1 break;
        proxy_pass  http://localhost:3000;
        proxy_read_timeout  90;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    include /var/www/example/www/nginx.conf;
    include snippets/wordpress.conf;
}

Gitea config
APP_NAME = Gitea
RUN_USER = gitea
RUN_MODE = prod

[server]
#PROTOCOL = https    #https complains about a cert. I want nginx to handle ssl.
DOMAIN           = example.com
ROOT_URL         = https://example.com/git/   # See, it's set
# STATIC_URL_PREFIX = /git/   # Did not help. I was only able to get static assets w/ nginx
LFS_JWT_SECRET   = xxxxx
SSH_DOMAIN       = example.com
HTTP_PORT        = 3000
DISABLE_SSH      = false
SSH_PORT         = 22
LFS_START_SERVER = true
LFS_CONTENT_PATH = /var/lib/gitea/data/lfs
OFFLINE_MODE     = false

[database]
DB_TYPE  = mysql
HOST     = 127.0.0.1:3306
NAME     = xxxxx
USER     = xxxxx
PASSWD   = xxxxxx
LOG_SQL  = false
SCHEMA   =
SSL_MODE = disable
CHARSET  = utf8mb4
PATH     = /var/lib/gitea/data/gitea.db

[security]
INSTALL_LOCK       = true
SECRET_KEY         =
INTERNAL_TOKEN     = xxxxxx
PASSWORD_HASH_ALGO = xxxxx

[oauth2]
ENABLE = false

[U2F]
APP_ID =

[log]
MODE              = file
LEVEL             = info
# ROUTER = console
ENABLE_ACCESS_LOG = true
ACCESS            = file
ROOT_PATH         = /var/lib/gitea/log
ROUTER            = console

[service]
REGISTER_EMAIL_CONFIRM            = false
ENABLE_NOTIFY_MAIL                = false
DISABLE_REGISTRATION              = true
ALLOW_ONLY_EXTERNAL_REGISTRATION  = false
ENABLE_CAPTCHA                    = false
REQUIRE_SIGNIN_VIEW               = false
DEFAULT_KEEP_EMAIL_PRIVATE        = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = false
DEFAULT_ENABLE_TIMETRACKING       = true
NO_REPLY_ADDRESS                  = noreply.example.com
DEFAULT_USER_VISIBILITY           = private
DEFAULT_ORG_VISIBILITY            = private
REQUIRE_SIGNIN_VIEW               = true
DISABLE_USERS_PAGE                = true

[repository]
ROOT = /var/lib/gitea/data/gitea-repositories

[mailer]
ENABLED = false

[picture]
DISABLE_GRAVATAR        = false
ENABLE_FEDERATED_AVATAR = false

[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false

[session]
PROVIDER = file

[ui]
DEFAULT_THEME = gitea
THEMES = auto,gitea,arc-green

Last 1000 lines of the gitea log.
gitea1000.txt

Gitea Version

1.16.8-1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.30.2-1

Operating System

Debian stable

How are you running Gitea?

Gitea 1.16.8-1 debian package from https://gitlab.com/packaging/gitea
No static assets included, so I built them after downloading the repo.
Running on a debian linux VPS w/ a sysvinit script.
Proxy via nginx 1.18.0-6.1.
Data stored in mariadb 10.5.15-0.

Database

MySQL

@wxiaoguang
Copy link
Contributor

You are using wrong Gitea static (asset) files. The warning is only added in Gitea 1.17 which hasn't been released. But you said you are running Gitea 1.16.8-1 debian package

@wxiaoguang
Copy link
Contributor

And I have checked the https://gitlab.com/packaging/gitea/-/blob/master/.gitlab-ci.yml

They are using Gitea binary from https://dl.gitea.io/gitea/, which includes static assets. Do not compile the static assets if you do not know how it works.

@TokisanGames
Copy link
Author

Thank you. Nothing I could do allowed the server to display images or css until I built them myself and setup static hosting w/ nginx. It was my mistake in selecting the wrong repo. There are no static assets in the debian package:

# dpkg -L gitea
/.
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/gitea.service
/usr
/usr/bin
/usr/bin/gitea
/usr/share
/usr/share/doc
/usr/share/doc/gitea
/usr/share/doc/gitea/changelog.Debian.gz
/usr/share/doc/gitea/changelog.gz

# dpkg -l gitea\*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-===================================
ii  gitea          1.16.8-1     amd64        A painless self-hosted Git service.

@TokisanGames
Copy link
Author

After I built the static assets from the correct repo, the error on top and the 404s on the dashboard did indeed go away.
Thanks again.

@wxiaoguang
Copy link
Contributor

Actually, you do not need to compile that manually.

All static assets are embedded inside Gitea binary already. They are served under http://..../assets/....

@TokisanGames
Copy link
Author

I see. However I'm not able to retrieve the builtin ones via web browser (via ssl, in a subdirectory). My console reports:

example.com/:77          GET https://example.com/git/assets/img/logo.svg 404
example.com/:610          GET https://example.com/git/assets/js/index.js?v=6765b707120e1e5736d66531d590dceb net::ERR_ABORTED 404
favicon.png:1          GET https://example.com/git/assets/img/favicon.png 404
logo.svg:1          GET https://example.com/git/assets/img/logo.svg 404

I've tried all variations of ROOT_URL, STATIC_URL_PREFIX, and PROTOCOL that I could think of, or saw on other issues. Nor could I get the logging to report individual file access and tell me what the issue was. The only way I was able to get the assets to the browser was by building them myself, and including an additional nginx location block to pull them directly, as I showed in my config:

    # Gitea
    location ^~ /git/assets/ {
       root        /var/lib/gitea/public;
        rewrite     ^/git/assets/(.*)$ /$1 break;
        access_log  /var/lib/gitea/log/nginx_access.log;
        error_log   /var/lib/gitea/log/nginx_error.log;
        try_files   $uri =404;
    }

    location /git/ {
        access_log  /var/lib/gitea/log/nginx_access.log;
        error_log   /var/lib/gitea/log/nginx_error.log;
        rewrite     ^/git/(.*)$ /$1 break;
        proxy_pass  http://localhost:3000;
        proxy_read_timeout  90;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

I have it working now, and thanks to your help, no more error messages.

@wxiaoguang
Copy link
Contributor

If you follow the doc strictly (including the trailing slash or not), there shouldn't be any problem.

https://docs.gitea.io/en-us/reverse-proxies/#nginx-with-a-sub-path

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants