Reverse proxy for the Gemini protocol
To redirect Gemini traffic to a specific server, we can create a reverse proxy with Nginx in a relatively simple way. The use case is the following: A domain points to server A, but the Gemini server is on server B. In short, we need to redirect Gemini traffic from one server to another.
Requirements
- Domain pointing to the server IP. For example,
gemini.example.compoints to the server where Nginx is installed. In this case, server A. - Nginx installed and running. Otherwise we can install it with
apt install nginxif we are on a Debian-based system. It must be on server A. - Gemini server up and running. In this case, server B.
If we are ready, we can start.
Nginx configuration
Nginx is not prepared to handle the Gemini protocol by default, so we will solve it by installing an additional module to be able to redirect ports. If you are used to working with unix commands, you could also use socat or nc.
We install the module with the following command, if you use Debian or Ubuntu:
apt install libnginx-mod-stream
Once installed, we can add the necessary configuration to redirect Gemini traffic to a specific server.
Inside the Nginx configuration, in /etc/nginx/nginx.conf, we add the following block:
stream {
upstream gemini {
server 1.2.3.4:1965;
}
server {
listen 1965;
proxy_pass gemini;
}
}
The address 1.2.3.4 is the IP of the server where we want to redirect the traffic (IP of server B). Port 1965 is the default port of the Gemini protocol.
We save the changes and restart Nginx.
systemctl restart nginx
We are done! See? It was not that complicated.
Remember that your Gemini server must manage the TLS certificates, since Nginx cannot do it for you with the current configuration. I recommend using Agate, a Gemini server written in Rust that creates and self-signs the certificates automatically.
Keep reading about Gemini
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Support me on Ko-fi
Comments
There are no comments yet.