From: nutomic Date: Thu, 24 Sep 2020 13:50:38 +0000 (+0000) Subject: Fix nginx config for local federation setup (#104) X-Git-Url: http://these/git/%22%7Burl%7D/static/%7B%7D/%7Bpost.url%7D?a=commitdiff_plain;h=e8ea0664ef0a355561a0f8878e1400b23d34893c;p=lemmy.git Fix nginx config for local federation setup (#104) Fix depends_on Add note about different port for backend in federation docs Fix nginx config for local federation setup Co-authored-by: Felix Ableitner Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/104 --- diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 2a6e24b2..b4181e5d 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -15,11 +15,11 @@ services: depends_on: - pictrs - iframely - - lemmy-alpha - - lemmy-beta - - lemmy-gamma - - lemmy-delta - - lemmy-epsilon + - lemmy-alpha-ui + - lemmy-beta-ui + - lemmy-gamma-ui + - lemmy-delta-ui + - lemmy-epsilon-ui pictrs: restart: always diff --git a/docker/federation/nginx.conf b/docker/federation/nginx.conf index f787a9d2..003f88dc 100644 --- a/docker/federation/nginx.conf +++ b/docker/federation/nginx.conf @@ -3,6 +3,12 @@ events { } http { + upstream lemmy-alpha { + server "lemmy-alpha:8541"; + } + upstream lemmy-alpha-ui { + server "lemmy-alpha-ui:1234"; + } server { listen 8540; server_name 127.0.0.1; @@ -11,14 +17,19 @@ http { # Upload limit for pictshare client_max_body_size 50M; - location /api/v1 { - proxy_pass http://lemmy-alpha:8541/api/v1; + location ~ ^/(api|docs|pictrs|feeds|nodeinfo|.well-known) { + proxy_pass http://lemmy-alpha; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { - proxy_pass http://lemmy-alpha-ui:1234; + set $proxpass http://lemmy-alpha-ui; + if ($http_accept = "application/activity+json") { + set $proxpass http://lemmy-alpha; + } + proxy_pass $proxpass; + proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -34,6 +45,12 @@ http { } } + upstream lemmy-beta { + server "lemmy-beta:8551"; + } + upstream lemmy-beta-ui { + server "lemmy-beta-ui:1234"; + } server { listen 8550; server_name 127.0.0.1; @@ -42,14 +59,19 @@ http { # Upload limit for pictshare client_max_body_size 50M; - location /api/v1 { - proxy_pass http://lemmy-beta:8551/api/v1; + location ~ ^/(api|docs|pictrs|feeds|nodeinfo|.well-known) { + proxy_pass http://lemmy-beta; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { - proxy_pass http://lemmy-beta-ui:1234; + set $proxpass http://lemmy-beta-ui; + if ($http_accept = "application/activity+json") { + set $proxpass http://lemmy-beta; + } + proxy_pass $proxpass; + proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -65,6 +87,12 @@ http { } } + upstream lemmy-gamma { + server "lemmy-gamma:8561"; + } + upstream lemmy-gamma-ui { + server "lemmy-gamma-ui:1234"; + } server { listen 8560; server_name 127.0.0.1; @@ -73,14 +101,19 @@ http { # Upload limit for pictshare client_max_body_size 50M; - location /api/v1 { - proxy_pass http://lemmy-gamma:8561/api/v1; + location ~ ^/(api|docs|pictrs|feeds|nodeinfo|.well-known) { + proxy_pass http://lemmy-gamma; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { - proxy_pass http://lemmy-gamma-ui:1234; + set $proxpass http://lemmy-gamma-ui; + if ($http_accept = "application/activity+json") { + set $proxpass http://lemmy-gamma; + } + proxy_pass $proxpass; + proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -96,6 +129,12 @@ http { } } + upstream lemmy-delta { + server "lemmy-delta:8571"; + } + upstream lemmy-delta-ui { + server "lemmy-delta-ui:1234"; + } server { listen 8570; server_name 127.0.0.1; @@ -104,14 +143,19 @@ http { # Upload limit for pictshare client_max_body_size 50M; - location /api/v1 { - proxy_pass http://lemmy-delta:8571/api/v1; + location ~ ^/(api|docs|pictrs|feeds|nodeinfo|.well-known) { + proxy_pass http://lemmy-delta; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { - proxy_pass http://lemmy-delta-ui:1234; + set $proxpass http://lemmy-delta-ui; + if ($http_accept = "application/activity+json") { + set $proxpass http://lemmy-delta; + } + proxy_pass $proxpass; + proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -127,6 +171,12 @@ http { } } + upstream lemmy-epsilon { + server "lemmy-epsilon:8581"; + } + upstream lemmy-epsilon-ui { + server "lemmy-epsilon-ui:1234"; + } server { listen 8580; server_name 127.0.0.1; @@ -135,14 +185,19 @@ http { # Upload limit for pictshare client_max_body_size 50M; - location /api/v1 { - proxy_pass http://lemmy-epsilon:8581/api/v1; + location ~ ^/(api|docs|pictrs|feeds|nodeinfo|.well-known) { + proxy_pass http://lemmy-epsilon; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { - proxy_pass http://lemmy-epsilon-ui:1234; + set $proxpass http://lemmy-epsilon-ui; + if ($http_accept = "application/activity+json") { + set $proxpass http://lemmy-epsilon; + } + proxy_pass $proxpass; + proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/docs/src/contributing_federation_development.md b/docs/src/contributing_federation_development.md index 1d243603..0c6fd9c4 100644 --- a/docs/src/contributing_federation_development.md +++ b/docs/src/contributing_federation_development.md @@ -21,10 +21,12 @@ lemmy-epsilon | lemmy_epsilon | [127.0.0.1:8580](http://127.0.0.1:8580) | uses b You can log into each using the instance name, and `lemmy` as the password, IE (`lemmy_alpha`, `lemmy`). -To start federation between instances, visit one of them and search for a user, community or post, like this: -- `!main@lemmy-alpha:8540` -- `http://lemmy-beta:8550/post/3` -- `@lemmy-gamma@lemmy-gamma:8560` +To start federation between instances, visit one of them and search for a user, community or post, like this. Note that +the Lemmy backend runs on a different port than the frontend, so you have to increment the port number from +the URL bar by one. +- `!main@lemmy-alpha:8541` +- `http://lemmy-beta:8551/post/3` +- `@lemmy-gamma@lemmy-gamma:8561` Firefox containers are a good way to test them interacting.