Merge branch 'main' into wildcard

This commit is contained in:
muppeth 2023-12-29 14:11:16 +00:00
commit 41b95fb710
3 changed files with 34 additions and 50 deletions

View File

@ -7,10 +7,10 @@
include_tasks: config.yml
- name: "[NGINX] - Set SSL configuration"
include: ssl.yml
include_tasks: ssl.yml
- name: '[NGINX] - Deploy TOR for onion hidden services'
include: tor.yml
include_tasks: tor.yml
when: enable_tor == 'true'
- name: '[NGINX] - Create onion addresses'

View File

@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{% extends "core.j2" %}
{% block app_specific %}

View File

@ -1,25 +1,42 @@
limit_req_zone $binary_remote_addr zone={{ item.name }}_ratelimit:10m rate=1r/s;
{% extends "core.j2" %}
{% block extra_upstreams %}
upstream lemmy {
server "{{ item.upstream_name }}:{{ item.lemmy_port }}";
}
upstream lemmy-ui {
server "{{ item.upstream_name }}:{{ item.lemmy_ui_port }}";
}
{% endblock %}
{% block headers %}
# Various content security headers
add_header Referrer-Policy "same-origin";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "DENY";
add_header X-XSS-Protection "1; mode=block";
{% endblock %}
{% block location %}
# frontend
location / {
# The default ports:
# lemmy_ui_port: 1235
# lemmy_port: 8536
set $proxpass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_ui_port }};
if ($http_accept = "application/activity+json") {
set $proxpass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_port }};
set $proxpass "{{ item.upstream_proto }}://lemmy-ui";
if ($http_accept ~ "application/activity+json") {
set $proxpass "{{ item.upstream_proto }}://lemmy";
}
if ($http_accept = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") {
set $proxpass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_port }};
}
if ($request_method = POST) {
set $proxpass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_port }};
if ($request_method = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") {
set $proxpass "{{ item.upstream_proto }}://lemmy";
}
proxy_pass $proxpass;
rewrite ^(.+)/+$ $1 permanent;
# Send actual client IP upstream
@ -29,8 +46,8 @@ location / {
}
# backend
location ~ ^/(api|feeds|nodeinfo|.well-known) {
proxy_pass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_port }};
location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
proxy_pass {{ item.upstream_proto }}://lemmy;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
@ -38,48 +55,11 @@ location ~ ^/(api|feeds|nodeinfo|.well-known) {
# Rate limit
#limit_req zone={{ item.name }}_ratelimit burst=30 nodelay;
# Send actual client IP upstream
# 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;
}
{% if lemmy_pictrs_deploy == true %}
# pictrs only - for adding browser cache control.
location ~ ^/(pictrs) {
# allow browser cache, images never update, we can apply long term cache
expires 120d;
add_header Pragma "public";
add_header Cache-Control "public";
proxy_pass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ lemmy_port }};
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Rate limit
limit_req zone={{ item.name }}_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;
}
{% endif %}
{% endblock %}
# Anonymize IP addresses
# https://www.supertechcrew.com/anonymizing-logs-nginx-apache/
#map $remote_addr $remote_addr_anon {
# ~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
# ~(?P<ip>[^:]+:[^:]+): $ip::;
# 127.0.0.1 $remote_addr;
# ::1 $remote_addr;
# default {{ item.upstream_name }};
#}