Hosting several sites on the same host

Adrian Hesketh adrianhesketh at hushmail.com
Tue Dec 15 22:38:54 GMT 2020


I don't know if it will help you, but here's a walkthrough of how my
Go implementation. It's quite tied to the Go implementation, but there
may be similar capabilities in PHP.
Firstly, the server keeps a map of the domain name to the underlying
Gemini handler (the code that processes the request), and the TLS
certificate to be used for that domain. The Go TLS library allows a
"GetCertificate" function to be added to the TLS configuration. This
"GetCertificate" function is called during the TLS handshake and
returns the certificate to present to the client (dh.KeyPair) based on
the hostname being requested during the handshake.
https://github.com/a-h/gemini/blob/598044444c08befc3c01bafe5558a5decb83ab40/server.go#L180
With that configuration in place, the server enters a loop that
listens for new incoming connections:
https://github.com/a-h/gemini/blob/598044444c08befc3c01bafe5558a5decb83ab40/server.go#L197
When a new connection is received, it's handled in another goroutine
(similar to a thread) by the handleTLS function. This allows the loop
to listen for new connections while content is being served by the
goroutine.
https://github.com/a-h/gemini/blob/598044444c08befc3c01bafe5558a5decb83ab40/server.go#L211
Now that the handshake is over, but the Gemini request/response needs
to take place, the handleTLS function has to read the domain name
again to look up which Gemini handler to use for the domain that was
accessed:
https://github.com/a-h/gemini/blob/598044444c08befc3c01bafe5558a5decb83ab40/server.go#L235
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.orbitalfox.eu/archives/gemini/attachments/20201215/7988798b/attachment-0001.htm>


More information about the Gemini mailing list