feat(nginx): Generate configs using a template

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2547>
This commit is contained in:
Georg Krause 2023-08-01 13:31:51 +02:00 committed by Marge
commit 88d7bdb8ab
7 changed files with 362 additions and 63 deletions

View file

@ -1,5 +1,7 @@
upstream funkwhale-api {
server ${FUNKWHALE_API_HOST}:${FUNKWHALE_API_PORT};
# depending on your setup, you may want to update this
server ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT};
}
# Required for websocket support.
@ -8,18 +10,18 @@ map $http_upgrade $connection_upgrade {
'' close;
}
server {
listen 80;
listen [::]:80;
charset utf-8;
server_name _;
add_header Content-Security-Policy "default-src 'self'; connect-src https: wss: http: ws: 'self' 'unsafe-eval'; script-src 'self' 'wasm-unsafe-eval'; style-src https: http: 'self' 'unsafe-inline'; img-src https: http: 'self' data:; font-src https: http: 'self' data:; media-src https: http: 'self' data:; object-src 'none'";
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Service-Worker-Allowed "/";
# General configs
root /usr/share/nginx/html;
client_max_body_size ${NGINX_MAX_BODY_SIZE};
charset utf-8;
# compression settings
gzip on;
@ -27,7 +29,6 @@ server {
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
application/javascript
application/vnd.geo+json
@ -48,6 +49,12 @@ server {
text/x-cross-domain-policy;
# end of compression settings
# headers
add_header Content-Security-Policy "default-src 'self'; connect-src https: wss: http: ws: 'self' 'unsafe-eval'; script-src 'self' 'wasm-unsafe-eval'; style-src https: http: 'self' 'unsafe-inline'; img-src https: http: 'self' data:; font-src https: http: 'self' data:; media-src https: http: 'self' data:; object-src 'none'";
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Service-Worker-Allowed "/";
location /api/ {
include /etc/nginx/funkwhale_proxy.conf;
# This is needed if you have file import via upload enabled.
@ -56,16 +63,16 @@ server {
}
location / {
alias /usr/share/nginx/html/;
expires 1d;
alias /usr/share/nginx/html/;
try_files $uri $uri/ /index.html;
}
location ~ "/(front/)?embed.html" {
alias /usr/share/nginx/html/embed.html;
add_header Content-Security-Policy "connect-src https: http: 'self'; default-src 'self'; script-src 'self' unpkg.com 'unsafe-inline' 'unsafe-eval'; style-src https: http: 'self' 'unsafe-inline'; img-src https: http: 'self' data:; font-src https: http: 'self' data:; object-src 'none'; media-src https: http: 'self' data:";
add_header Referrer-Policy "strict-origin-when-cross-origin";
alias /usr/share/nginx/html/embed.html;
expires 1d;
}
@ -131,4 +138,5 @@ server {
# If the reverse proxy is terminating SSL, nginx gets confused and redirects to http, hence the full URL
return 302 ${FUNKWHALE_PROTOCOL}://${FUNKWHALE_HOSTNAME}/api/v1/instance/spa-manifest.json;
}
}