💾 Archived View for gemini.sh0.xyz › log › 2023-03-11_running_multiple_servers.gmi captured on 2024-05-26 at 14:49:14. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-03-20)
-=-=-=-=-=-=-
When I started my gemini capsule I added some hobby stuff to the page. Specifically info about amateur radio. My webpage for amateur radio is pretty "old school" with no JS, very little CSS and all generated using Linux command line tools. As I never remember to update it I thought I might as well make the transition to just use Gemini and point my gemini to http proxy and all is good.
The issue is I already have this capsule running on my VPS where I also host that page. I could use a different port but that is always sucks. Similar to how hosting multiple sites on a single box, I found that you can use nginx to proxy incoming connections based on the SSL cert used and direct them to a specific server. Setup multiple gemini servers on different ports and now I have both pages working:
Two changes needed to be done:
Next to the http section in your nginx.conf file, the following can be added to support streams and direct them to a proxy server based on TLS Server Name Indication (SNI) address reported.
In nginx.conf load the module:
load_module /usr/lib/nginx/modules/ngx_stream_module.so;
Then after the http section add the following configuration:
stream { # connection-limiting limit_conn_zone $binary_remote_addr zone=addr:10m; limit_conn_log_level warn; limit_conn addr 1; # logging log_format basic '$remote_addr $upstream_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received ' '$session_time'; access_log /var/log/nginx/gemini.access.log basic; error_log /var/log/nginx/error.log warn; # map SNI -> backend service map $ssl_preread_server_name $name { gemini.sh0.xyz sh0; ad0qm.com ad0qm; } # Gemini server { listen 1965; ssl_preread on; proxy_buffer_size 16k; # pass requests directly to the corresponding Gemini server proxy_pass $name; } upstream ad0qm { server 127.0.0.1:1966; } upstream sh0 { server 127.0.0.1:1967; } }
Add entries to the map and an upstream for each server you want to connect.
Thanks to prouxi over on Reddit for the config file.
Systemd supports instances by creating service files with @ in the name. The value after @ can be used in the service file, just put %i in any value.
/lib/systemd/system/molly-brown@.service
[Unit] Description=Molly Brown gemini server After=network.target [Service] Type=simple Restart=always User=molly ExecStart=/usr/local/bin/molly-brown -c /etc/molly-%i.conf [Install] WantedBy=multi-user.target
I created two config files, /etc/molly-sh0.conf and /etc/molly-ad0qm.conf. Each has a different port configured. Start and enable both:
$ sudo systemctl start molly-brown@sh0 $ sudo systemctl enable molly-brown@sh0 $ sudo systemctl start molly-brown@ad0qm $ sudo systemctl enable molly-brown@ad0qm
$ published: 2023-03-11 23:20 $
$ tags: #gemini $
-- CC-BY-4.0 jecxjo 2023-03-11