Hi, how do you run forgejo under a reverse proxy while using an ssh channel to pull/push commits?
From what I understand caddy is only able to proxy http traffic.
IIRC there is a plugin for Caddy that can do what you are looking for.
Edit: here you go
This would only work if there is no other traffic on the port being used (eg: port 22). If both the host SSH service and Forgejo SSH service expect traffic on port 22, then this would not work since server name indication (SNI) is not provided with SSH traffic and Caddy would not be able to identify the appropriate destination for multiple SSH services traffic.
I dont know about caddy but nginx proxy manager does this very well. Also, if running in docker, you can expose the port that runs ssh for forgejo und a different port than the host machine‘s (eg 2222). In that case you just put the remote in with the port and call it a day.
I don’t think you can with caddy
Not really through Caddy but for my setup I have it so the ssh port for Forgejo is only accessible through tailscale. So for push/pulling updated my ssh config file to something like
Host git.mysite.com HostName tailscaleMachineName User git Port 1234
Then doing git pull git@git.mysite.com:user/project.git works just fine as long as I am connected to tailscale
Otherwise you could open the port for Forgejo’s ssh so that you can access it without any vpn
deleted by creator
There seems to be mixed reactions to this suggestion. I don’t know enough to understand why.
I solved this by setting my changing a setting somewhere in forgejo to display the ssh url as something like ssh.mydomain.com so that I could keep my forgejo domain pointed to the reverse proxy but point git.mydomain.com to the forgejo container which has its own ip address. This is all for local traffic. For other traffic both domains point to my routers ip and I forward port 22 to the forgejo container.
I can’t give you the technical explanation, but it works.
My Caddyfile only something like this@forgejo host forgejo.pe1uca handle @forgejo { reverse_proxy :8000 }and everything else has worked properly cloning via ssh with
git@forgejo.pe1uca:pe1uca/my_repo.gitMy guess is git only needs the host to resolve the IP and then connects to the port directly.
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:
Fewer Letters More Letters DNS Domain Name Service/System Git Popular version control system, primarily for code HTTP Hypertext Transfer Protocol, the Web HTTPS HTTP over SSL IP Internet Protocol SFTP Secure File Transfer Protocol for encrypted file transfer, over SSH SSH Secure Shell for remote terminal access SSL Secure Sockets Layer, for transparent encryption TCP Transmission Control Protocol, most often over IP VPS Virtual Private Server (opposed to shared hosting) nginx Popular HTTP server
[Thread #962 for this sub, first seen 10th Sep 2024, 12:25] [FAQ] [Full list] [Contact] [Source code]
Afaik you can reverse proxy the ssh connection. I’ve been connecting to my server using the domain and tld (asudox.dev)
Are you able to provide some details on how you are doing this? I don’t think you can do much with reverse proxies and SSH beyond routing all traffic on port 22 (or the configured SSH port) to whichever port SSH is listening on. In other words, the reverse proxy cannot route SSH traffic for the host on port 22 to the host, route SSH traffic for Forgejo on port 22 to Forgejo’s SSH process, and SFTP traffic on port 22 to the SFTP process - at least not via domain name like a HTTP/HTTPS reverse proxy would work.
Instead, this would need to be done via IP address where the host SSH process listens on 192.168.1.2, the Forgejo SSH process listens on 192.168.1.3, and the SFTP process listens on 192.168.4. Otherwise, each of those services would need to use different ports.
If both Caddy and Forgejo are running in Docker containers you could do SSH Container Passthrough.
Link is to Gitea docs but should work fine with Forgejo.
It works but I don’t think Forgejo plans to support it in the future. Gitea and Forgejo started to diverge and the documentation regarding docker is somewhat in a deprecated state.
Edit: I also think the OP’s question is different from this. So this might not be a solution.
There are a few ways to do it:
- host SSH on port 22, forgejo on a different port. Expose both ports to the internet
- host SSH on a different port, forgejo on port 22. Expose both ports to the internet
- host SSH on port 22. Forgejo on port 2222. Only 22 exposed to the internet. Change the authorized_keys user of the git user on host to automatically call the internal forgejo SSH app
Last option is how I run my Gitea instance, authorized keys is managed by gitea so you don’t really need to do anything high maintenance.
~git/.ssh/authorized_keys:
command="/usr/local/bin/gitea --config=/data/gitea/conf/app.ini serv key-9",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,no-user-rc,restrict ssh-rsa PUBLICKEYHASH/usr/local/bin/gitea:
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.14 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"127.0.0.14 is the local git docker access where I expose the service, but you couldn’t different ports, IPS, etc.
There’s really no need to reverse proxy ssh. What are you attempting to accomplish with the reverse proxy exactly? Http proxying allows you to add things like TLS encryption and modify headers. But ssh is a secure protocol already and you can’t really modify much in transit.
Use something that can do TCP, i.e. HAProxy, NGINX or Apache
If you connect from outside your LAN, you would need to forward the ssh port to the server in your router settings. If you are inside the LAN, just use the ip address of the forgejo server.








