Today I am setting up reverse proxies for some of my applications. While I'm comfortable with using IP addresses, I recognize the usefulness of having a nice name like git.laurii.lan instead of 192.168.1.200.

First on the list is the git repository where I have some code (including the ansible stuff for setting things up). The main reason is that, when I've set up gitea, I named the vm gitea.laurii.lan and I was ending up changing the URL in the .git directory after each checkout, because the origin url was named:

Gitea URL

I told myself I lived long enough with this :)

A tale of two parts

I figured that I need to create a new nginx site configuration, but the url above must come from somewhere...

Gitea

After digging a bit, I found that all of Gitea's configuration is in an .ini file /usr/local/etc/gitea/conf/app.ini. We will want to update the [server] section:

[server]
DOMAIN       = git.laurii.lan
HTTP_ADDR    = <YOUR GITEA SERVER ADDRESS>
HTTP_PORT    = 3000
ROOT_URL     = http://%(DOMAIN)s/
DISABLE_SSH  = false

Once we change this and restart gitea, we'll get the url shown in the screenshot above. The consequence is that when a repo is checked out, the origin will be set up to that URL.

NGINX

As I'm not too familiar with nginx configurations (I learn with each reverse proxy config I do), I started with the internet, and gitea's website has a nice config:

server {
    listen 80;
    server_name git.example.com;

    location / {
        proxy_pass http://<YOUR GITEA SERVER ADDRESS>:3000;
    }
}

Few considerations

Bonus

Here's my ansible config for the reverse proxy:

# You need to change the ROOT_DIR in
# Gitea's /usr/local/etc/gitea/conf/app.ini
# to match the server name.
#
# [server]
# DOMAIN       = git.laurii.lan
# HTTP_ADDR    = <ip address>
# HTTP_PORT    = 3000
# ROOT_URL     = http://%(DOMAIN)s/
# DISABLE_SSH  = false

server {
    listen 80;
    server_name {{ site_name }};

    access_log  /var/log/nginx/{{ site_name }}_access.log;
    error_log   /var/log/nginx/{{ site_name }}_error.log;

    location / {
        proxy_pass {{ site_internal_url }};
    }
}
  • my Gitea instance runs on a TrueNas Jail, just because there's a plugin and was easy to configure. I had to edit the app.ini file by hand and restart the jail. If you're in the same situation, you might think prepare the plugin with the proper [server] config, as you intend to have it via reverse proxy.
  • I don't have HTTPS set up yet, this will come later
  • My gitea version at the time of writhing this is 1.13.6.

HTH,