+ services.nginx = let
+ ui = "http://127.0.0.1:${toString cfg.ui.port}";
+ backend = "http://127.0.0.1:${toString cfg.settings.port}";
+ in mkIf cfg.nginx.enable {
+ enable = mkDefault true;
+ appendHttpConfig = ''
+ map "$request_method:$http_accept" $proxpass {
+ # If no explicit matches exists below, send traffic to lemmy-ui
+ default "${ui}";
+
+ # GET/HEAD requests that accepts ActivityPub or Linked Data JSON should go to lemmy.
+ #
+ # These requests are used by Mastodon and other fediverse instances to look up profile information,
+ # discover site information and so on.
+ "~^(?:GET|HEAD):.*?application\/(?:activity|ld)\+json" "${backend}";
+
+ # All non-GET/HEAD requests should go to lemmy
+ #
+ # Rather than calling out POST, PUT, DELETE, PATCH, CONNECT and all the verbs manually
+ # we simply negate the GET|HEAD pattern from above and accept all possibly $http_accept values
+ "~^(?!(GET|HEAD)).*:" "${backend}";
+ }
+ '';
+ virtualHosts."${cfg.settings.hostname}".locations = {
+ "~ ^/(api|pictrs|feeds|nodeinfo|.well-known)" = {
+ # backend requests
+ proxyPass = backend;
+ proxyWebsockets = true;
+ recommendedProxySettings = true;
+ };
+ "/" = {
+ # mixed frontend and backend requests, based on the request headers
+ proxyPass = "$proxpass";
+ recommendedProxySettings = true;