Skip to content

Commit e8cc194

Browse files
committed
Add quickstart guide for ohttp-relay on basic ubuntu server
This issue payjoin/ohttp-relay#37 outlines a need for some documentation for a quickstart guide on a docker server with a nginx proxy. This iteration uses the existing dockerfile with a nginx reverse proxy in front.
1 parent 9ea05ed commit e8cc194

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Quickstart ohttp relay
2+
3+
We'll demonstrate how you can setup an ohttp server on common cloud insfrastructure on something like [AWS Ubuntu](https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/gs-ubuntu.html) using the `ohttp-relay` crate in Payjoin Dev Kit. This should take about 30 minutes.
4+
5+
## Initial server setup
6+
7+
We will be using a basic Ubuntu server in our tutorial. In this tutorial we will be running the server as a docker container with nginx as a TLS proxy.
8+
9+
First, you must install docker and nginx on your server.
10+
11+
Install docker, nginx and the ningx stream module on a fresh Ubuntu server:
12+
13+
```sh
14+
sudo apt update && sudo apt upgrade -y # Ubuntu
15+
16+
sudo apt install -y docker.io nginx libnginx-mod-stream #libnginx-mod-stream gives us access to the nginx stream module
17+
18+
sudo systemctl start docker nginx
19+
sudo systemctl enable docker nginx
20+
```
21+
22+
## Deploy ohttp-relay with Docker
23+
24+
We will want to build our docker image for our server to run as a container from.
25+
26+
Clone our ohttp-relay from github and then build the docker image.
27+
28+
```sh
29+
git clone https://github.com/payjoin/ohttp-relay.git
30+
31+
cd ohttp-relay
32+
33+
sudo docker build -t ohttp-relay .
34+
```
35+
36+
## Configure Nginx as a Reverse Proxy
37+
38+
Edit the existing `nginx.conf`.
39+
40+
```sh
41+
#/etc/nginx/nginx.conf
42+
load_modules /usr/lib/nginx/modules/ngx_mod_stream.so;
43+
error_log /var/log/nginx/error.log debug;
44+
pid /var/run/nginx.pid;
45+
46+
events {
47+
worker_connections 1024;
48+
}
49+
50+
stream {
51+
server {
52+
listen 80;
53+
54+
proxy_pass 127.0.0.1:3000;
55+
}
56+
57+
server {
58+
listen 443 ssl;
59+
60+
ssl_certificate /etc/nginx/ssl/cert.pem;
61+
ssl_certificate_key /etc/nginx/ssl/key.pem;
62+
63+
proxy_pass 127.0.0.1:3000;
64+
}
65+
}
66+
67+
```
68+
69+
Restart your nginx service
70+
71+
```sh
72+
sudo systemctl restart nginx
73+
```
74+
75+
## Ensure the ohttp-relay runs persistently
76+
77+
We can use some built-in flags in docker to run our ohttp-relay in the background.
78+
79+
```sh
80+
sudo docker run -d --restart unless-stopped --name ohttp-relay -p 3000:3000 \
81+
-e PORT=3000 \
82+
-e GATEWAY_ORIGIN=https://payjo.in \
83+
ohttp-relay
84+
```
85+
86+
the `-d` flag ensures that our container will be running in the background and `--restart unless stopped` will ensure persistence even after logging and server reboots.
87+
88+
That's all it takes to setup an ohttp-relay. The looping allows a sender to send a proposal and receive a Payjoin in an asynchronous way. When you run this program you will participate in coordinating payjoins by relaying data between senders and receivers without .
89+
90+
## Testing
91+
92+
Check your work by running the curl request below to do a quick check to make sure your server is receiving well.
93+
94+
For testing we will include th `-vk and --proxy-insecure` flags to ensure we can get past any warnings or errors our curl request might send us with invalid cert signatures. For final checks in prod we recommend removing these flags to ensure your keys and certs are working and up-to-date.
95+
96+
This curl request should occur in 2 stages
97+
1. The proxy CONNECT request that passes through your relay to the `https://payjo.in` directory
98+
2. The GET request on `/ohttp-keys` that will return a binary encoded output
99+
A successful test should return a 200/OK response on both of these steps
100+
101+
```sh
102+
curl -vk --proxy-insecure --proxy https://{your-relay-public-ip} https://payjo.in/ohttp-keys --output -
103+
```

0 commit comments

Comments
 (0)