Setup of a niltalk chatserver behind an Apache reverse https proxy
Since our generic proxy approach does not work out of the box for the niltalk chat server, we will see in this post how to put everything together for this case.
We assume thet we will run the talk server at the address https://talk.example.com
.
Installing niltalk
Let’s login to out target machine and be sure, that we have no open port 9000 to the outer world.
If we do not want to build the server by ourselves, we get the binary:
After unpacking, we create a target directory
and copy the binary there
For the static web templates, we need to clone the niltalk git-respository
and to copy the static
directory also to the target folder:
To create a configuration, we have to run the server with the command
This creates a file config.toml
that we can amend later on as needed. For now, it makes sense to set the storage to memory
:
At this point we have the chat server installed. Running it by typing sudo /opt/nilserver/nilserver
should result in an open port 9000.
Creating the service
Since we want to start the talk server by default, we create a service file /lib/systemd/system/niltalk.service
with the following contents:
We enable the service by linking it to the right place:
Now we should be able to start and stop the service using the sudo service niltalk start
and sudo service niltalk stop
commands, respectively.
Apache reverse proxy
The standard approach does not work here. The talk server is using web sockets, which are not proxied/rewritten by default. So we have to amend our configuration to do that.
But first, we can go with the “standard” approach to get the certificate. The Apache talk.example.com.conf
configuration reads as
So we get our certificate via sudo certbot --apache -d talk.example.com
.
But now we have to add some configuration on the newly created talk.example.com-le-ssl.conf
:
So basically, we are enabling the websocket use for our proxy.
In order to avoid client reconnection every 5 minutes, we use a (maybe dirty, I’m open for better solutions) workaround and set the connection timeout in /etc/apache2/apache2.conf
to 12 hours:
In order to get this all working, we have to enable the Apache headers
module and to restart the webserver:
Finally, we have to set the right IP and URL in our niltalk config file /opt/niltalk/config.toml
:
After restarting the chat server by
we are done.
That’s it! Now we have a niltalk chatserver behind an Apache reverse https proxy.
Main source for the Apache config part: mattermost.