From 84ed650ceb03b4294fc210c82d66693c78e4a89f Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 15 Dec 2021 19:47:42 +0100 Subject: [PATCH] UP: Add common-proxies recipe. --- ...iedPush-with-Matrix-support-in-Gentoo.adoc | 137 ++++++++++++++---- 1 file changed, 105 insertions(+), 32 deletions(-) diff --git a/content/posts/Set-up-UnifiedPush-with-Matrix-support-in-Gentoo.adoc b/content/posts/Set-up-UnifiedPush-with-Matrix-support-in-Gentoo.adoc index a4848e1..c3a83a2 100644 --- a/content/posts/Set-up-UnifiedPush-with-Matrix-support-in-Gentoo.adoc +++ b/content/posts/Set-up-UnifiedPush-with-Matrix-support-in-Gentoo.adoc @@ -28,6 +28,7 @@ toc: true :url-gotify: https://gotify.net/ :url-push-examples: https://gotify.net/docs/pushmsg :url-common-proxies: https://github.com/UnifiedPush/common-proxies +:url-common-proxies-install: https://github.com/UnifiedPush/common-proxies/blob/main/docs/install.md I set up UnifiedPush because I wanted push notifications in FluffyChat without talking to Google. This was a bit more difficult than I imagined, so I'm writing @@ -74,45 +75,16 @@ server creates and uses a directory called `data/` in its current path. == Configure nginx -You will need the link:{url-nginx-lua}[lua module] for nginx and -link:{url-lua-cjson}[lua-cjson]. I will not cover TLS certificates here, there -are many good guides about that already. - -[TIP] -If you don't want to deal with the lua stuff, there is also the -link:{url-common-proxies}[UnifiedPush Common-Proxies] project that provides a -rewrite proxy that does the same. - -.Reinstall nginx with lua support and install lua-cjson in Gentoo -[source,shell] --------------------------------------------------------------------------------- -echo "www-servers/nginx NGINX_MODULES: http_lua" | sudo tee /etc/portage/package.use/gotify -echo "dev-lua/lua-cjson" | sudo tee -a /etc/portage/package.accept_keywords/gotify -sudo emerge -a1 www-servers/nginx -sudo emerge -a dev-lua/lua-cjson -sudo rc-service nginx restart --------------------------------------------------------------------------------- - -You may have to tell nginx its lua module where to find lua-cjson. In my case I -had to add `lua_package_cpath "/usr/share/lua/5.1/?.so;;";` above the `server` -block. The `;;` means that the previous value of `lua_package_cpath` should be -appended. +I will not cover TLS certificates here, there are many good guides about that +already. Copy the link:{url-nginx}[configuration example], edit `server_name`, change `listen 80;` to `listen [::]:443 ssl;` and `listen 443 ssl;` and change `proxy_pass` to `http://[::1]:7777`. You don't need the `upstream` bit. -Copy the link:{url-nginx-up}[configuration example for UnifiedPush] into your -`server` block and change `proxy_pass` to `http://[::1]:7777/message`. - -Copy the link:{url-nginx-matrix}[configuration example for Matrix] into your -`server` block and change `relay.example.tld` to your `server_name`. - .Your nginx configuration should look similar to this [source,nginx] -------------------------------------------------------------------------------- -lua_package_cpath "/usr/share/lua/5.1/?.so;;"; - server { listen 443 ssl; listen [::]:443 ssl; @@ -145,6 +117,107 @@ server { proxy_send_timeout 1m; proxy_read_timeout 1m; } +} +-------------------------------------------------------------------------------- + +Reload nginx and change the admin password in the web interface. + +=== common-proxies method + +This is the recommended method. link:{url-common-proxies}[UnifiedPush +Common-Proxies] is a rewrite-proxy that converts UnifiedPush messages to a +format that Gotify understands. If you're not on Gentoo, have a look at the +link:{url-common-proxies-install}[installation instructions] of the project. + +.Install UnifiedPush common-proxies in Gentoo +[source,shell] +-------------------------------------------------------------------------------- +echo -e "www-apps/up-common-proxies" | sudo tee -a /etc/portage/package.accept_keywords/gotify +sudo emerge -a www-apps/up-common-proxies +-------------------------------------------------------------------------------- + +Change the `listenAddr` and Gotify address in the config file +(`/etc/up-common-proxies/config.toml` on Gentoo) and add the UnifiedPush +locations to your nginx config. I will assume that common-proxies listens on +`[::1]:7778`. + +.Your config.toml should look similar to this +[source,toml] +-------------------------------------------------------------------------------- +listenAddr = "[::1]:7778" +verbose = true + +[gateway] + [gateway.matrix] + enabled = true +[rewrite] + [rewrite.fcm] + enabled = false + [rewrite.gotify] + enabled = true + address = "[::1]:7777" + scheme = "http" +-------------------------------------------------------------------------------- + +.Start common-proxies in Gentoo and make it automatically start at boot +[source,shell] +-------------------------------------------------------------------------------- +sudo rc-service up-common-proxies start +sudo rc-update add up-common-proxies +-------------------------------------------------------------------------------- + +.Your nginx configuration should look similar to this +[source,nginx] +-------------------------------------------------------------------------------- +server { + # […] + + location ~ ^/(FCM|UP|_matrix) { + proxy_pass http://[::1]:7778; + } +} +-------------------------------------------------------------------------------- + +Reload nginx. + +=== Lua method + +[WARNING] +The author of the lua-module warns that >=nginx-1.11.11 is still not an +officially supported target yet. You are on your own. Expect runtime failures, +memory leaks and other problems! + +You will need the link:{url-nginx-lua}[lua module] for nginx and +link:{url-lua-cjson}[lua-cjson]. + +.Reinstall nginx with lua support and install lua-cjson in Gentoo +[source,shell] +-------------------------------------------------------------------------------- +echo "www-servers/nginx NGINX_MODULES: http_lua" | sudo tee /etc/portage/package.use/gotify +echo "dev-lua/lua-cjson" | sudo tee -a /etc/portage/package.accept_keywords/gotify +sudo emerge -a1 www-servers/nginx +sudo emerge -a dev-lua/lua-cjson +sudo rc-service nginx restart +-------------------------------------------------------------------------------- + +You may have to tell nginx its lua module where to find lua-cjson. In my case I +had to add `lua_package_cpath "/usr/share/lua/5.1/?.so;;";` above the `server` +block. The `;;` means that the previous value of `lua_package_cpath` should be +appended. + +Copy the link:{url-nginx-up}[configuration example for UnifiedPush] into your +`server` block and change `proxy_pass` to `http://[::1]:7777/message`. + +Copy the link:{url-nginx-matrix}[configuration example for Matrix] into your +`server` block and change `relay.example.tld` to your `server_name`. + +.Your nginx configuration should look similar to this +[source,nginx] +-------------------------------------------------------------------------------- +lua_package_cpath "/usr/share/lua/5.1/?.so;;"; + +server { + # […] location /UP { access_by_lua_block{ @@ -184,7 +257,7 @@ server { } -------------------------------------------------------------------------------- -Reload nginx and change the admin password in the web interface. +Reload nginx. == Use UnifiedPush