]> Untitled Git - lemmy.git/blobdiff - ansible/templates/nginx.conf
Moving docs to join.lemmy.ml . Fixes #1396 (#1410)
[lemmy.git] / ansible / templates / nginx.conf
index 9f31140b26a4fa3d56cccbe5a46bbe53ce223d4a..675925a201780af567a00a740a2c59eb1f6b0105 100644 (file)
@@ -1,4 +1,4 @@
-proxy_cache_path /var/cache/lemmy_frontend levels=1:2 keys_zone=lemmy_frontend_cache:10m max_size=100m                 use_temp_path=off;
+limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s;
 
 server {
     listen 80;
@@ -36,7 +36,7 @@ server {
     # It might be nice to compress JSON, but leaving that out to protect against potential
     # compression+encryption information leak attacks like BREACH.
     gzip on;
-    gzip_types text/css application/javascript;
+    gzip_types text/css application/javascript image/svg+xml;
     gzip_vary on;
 
     # Only connect to this site via HTTPS for the two years
@@ -48,37 +48,62 @@ server {
     add_header X-Frame-Options "DENY";
     add_header X-XSS-Protection "1; mode=block";
 
-    # Upload limit for pictshare
-    client_max_body_size 50M;
+    # Upload limit for pictrs
+    client_max_body_size 20M;
 
+    # frontend
     location / {
-        proxy_pass http://0.0.0.0:8536;
-        proxy_set_header X-Real-IP $remote_addr;
-        proxy_set_header Host $host;
-        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
-        # WebSocket support
-        proxy_http_version 1.1;
-        proxy_set_header Upgrade $http_upgrade;
-        proxy_set_header Connection "upgrade";
-
-        # Proxy Cache
-        proxy_cache             lemmy_frontend_cache;
-        proxy_cache_use_stale   error timeout http_500 http_502 http_503 http_504;
-        proxy_cache_revalidate  on;
-        proxy_cache_lock        on;
-        proxy_cache_min_uses    5;
-    }    
-
-    location /pictshare/ {
-      proxy_pass http://0.0.0.0:8537/;
+      # The default ports:
+      # lemmy_ui_port: 1235
+      # lemmy_port: 8536
+
+      set $proxpass "http://0.0.0.0:{{ lemmy_ui_port }}";
+      if ($http_accept = "application/activity+json") {
+        set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
+      }
+      if ($http_accept = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") {
+        set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
+      }
+      if ($request_method = POST) {
+        set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
+      }
+      proxy_pass $proxpass;
+
+      rewrite ^(.+)/+$ $1 permanent;
+
+      # Send actual client IP upstream
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+    }
+
+    # backend
+    location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
+      proxy_pass http://0.0.0.0:{{ lemmy_port }};
+      proxy_http_version 1.1;
+      proxy_set_header Upgrade $http_upgrade;
+      proxy_set_header Connection "upgrade";
 
-      if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
-        add_header Cache-Control "public, max-age=31536000, immutable";
-      }   
+      # Rate limit
+      limit_req zone=lemmy_ratelimit burst=30 nodelay;
+
+      # Add IP forwarding headers
+      proxy_set_header X-Real-IP $remote_addr;
+      proxy_set_header Host $host;
+      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+    }
+
+
+    # Redirect pictshare images to pictrs
+    location ~ /pictshare/(.*)$ {
+      return 301 /pictrs/image/$1;
+    }
+
+    location /iframely/ {
+      proxy_pass http://0.0.0.0:8061/;
+      proxy_set_header X-Real-IP $remote_addr;
+      proxy_set_header Host $host;
+      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }
 }