aproxy/README.md

127 lines
3.7 KiB
Markdown
Raw Permalink Normal View History

2022-12-03 19:06:50 +00:00
# aproxy
2022-12-03 19:08:24 +00:00
Activity Pub Reverse Proxy Framework
this is a collection of OpenResty scripts that provide different functionality
on top of ActivityPub implementations.
2022-12-07 05:00:48 +00:00
## Installation
2022-12-03 19:08:24 +00:00
2022-12-07 05:00:48 +00:00
### the fuck is openresty
Get OpenResty: http://openresty.org/en/
For those not in the know, OpenResty is a "soft fork" of the god NGINX.
It adds various modules but the most important of them is Lua scripting
(provided by another god, LuaJIT)
It is an effective replacement to your NGINX installation, but you can have
them coexisting (say, NGINX on port 80, OpenResty being reverse proxied by
2022-12-07 05:03:23 +00:00
NGINX on port 8069, though I wouldn't recommend it in production environments).
2022-12-07 05:00:48 +00:00
2024-02-16 20:56:06 +00:00
### how does it work
aproxy has two "hooks" into openresty:
- initialization of the lua vm
- callback for every incoming request
initialization will run validation of your configuration file and check
if it is valid. if it is not you will see logs emitted about what failed
when a request comes in, the scripts declared in the aproxy config file will
be executed sequentially (TODO: ensure order on conf file is chain order).
each script has two types of callbacks: init and request
init callbacks are called when initializing the request, so that the script
may do some conversion or transform the config data into a more performant
in-memory structure.
request callbacks are called on each request, as directed by the main script.
scripts define which paths they want to attach to (via PCRE regex), and so
they can do their own filtering.
look at `scripts/webfinger_allowlist.lua` for an example of how this looks
in a simple form.
2022-12-07 05:00:48 +00:00
### actually installing aproxy
2024-02-16 20:56:06 +00:00
- get openresty installed
- keep in mind that the specifics of configuring openresty for a double reverse proxy setup aren't included here.
- instructions here are for aproxy's setup in an existing openresty installation
2022-12-07 05:03:23 +00:00
```sh
2022-12-07 05:00:48 +00:00
mkdir /opt
git clone https://gitdab.com/luna/aproxy
cd aproxy
mkdir /etc/aproxy
cp ./conf.lua /etc/aproxy/conf.lua
2024-02-16 20:56:06 +00:00
# keep in mind the default configuration will lead to your users not being discovered at all,
# it is provided as an example for you to modify.
2022-12-07 05:00:48 +00:00
$EDITOR /etc/aproxy/conf.lua
```
#### now to configuring openresty to use aproxy
Say, you already have your reverse proxy block to your instance as such:
```nginx
http {
server {
server_name example.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_pass http://localhost:4000;
}
}
}
```
You need to do the following:
- Configure OpenResty package path so that it can call aproxy.
2024-02-16 20:56:06 +00:00
- insert aproxy hooks for initialization and for callbacks on every request
2022-12-07 05:00:48 +00:00
2024-02-16 20:56:06 +00:00
It'll look something like this if you use a single `location /` block:
2022-12-07 05:00:48 +00:00
```nginx
2024-02-16 20:56:06 +00:00
# set this to 'on' after you have tested that it actually works.
# once you do that, performance will be increased
# while the friction to quickly debug aproxy will also be increased
lua_code_cache off;
lua_package_path '/opt/?.lua;/opt/aproxy/?.lua;;';
init_by_lua_block {
require("aproxy.main").init()
}
2022-12-07 05:00:48 +00:00
http {
server {
server_name example.com;
location / {
access_by_lua_block {
2024-02-16 05:13:37 +00:00
require("aproxy.main").access()
2022-12-07 05:00:48 +00:00
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_pass http://localhost:4000;
}
}
}
```
2022-12-03 19:08:24 +00:00
2022-12-07 05:02:43 +00:00
## Running the test suite
2022-12-06 18:53:20 +00:00
2022-12-07 05:03:23 +00:00
requires luarocks, luajit, and nothing else.
2022-12-06 21:25:26 +00:00
2022-12-06 21:24:25 +00:00
```sh
2022-12-06 21:25:26 +00:00
make testdeps
2022-12-06 18:53:20 +00:00
eval (luarocks-5.1 path --bin)
2022-12-06 21:25:26 +00:00
make test
2022-12-06 18:53:20 +00:00
```