nginx.template 5.33 KB
Newer Older
1
# This file was generated from funkwhale.template
2

3
upstream funkwhale-api {
Andrew Morgan's avatar
Andrew Morgan committed
4
    # depending on your setup, you may want to update this
5
    server ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT};
6
7
8
}

server {
9
10
11
    listen 80;
    listen [::]:80;
    # update this to match your instance name
12
    server_name ${FUNKWHALE_HOSTNAME};
13
14
15
    # useful for Let's Encrypt
    location /.well-known/acme-challenge/ { allow all; }
    location / { return 301 https://$host$request_uri; }
Luclu7's avatar
Luclu7 committed
16
17
}

18
19
20
21
22
23
# required for websocket support
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

Luclu7's avatar
Luclu7 committed
24
server {
25
26
    listen      443 ssl;
    listen [::]:443 ssl;
27
    server_name ${FUNKWHALE_HOSTNAME};
28

Luclu7's avatar
Luclu7 committed
29
    # TLS
30
31
    # Feel free to use your own configuration for SSL here or simply remove the
    # lines and move the configuration to the previous server block if you
Reg's avatar
Typos    
Reg committed
32
    # don't want to run funkwhale behind https (this is not recommended)
33
34
    # have a look here for let's encrypt configuration:
    # https://certbot.eff.org/all-instructions/#debian-9-stretch-nginx
Luclu7's avatar
Luclu7 committed
35
36
37
38
    ssl_protocols TLSv1.2;
    ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
39
40
    ssl_certificate     /etc/letsencrypt/live/${FUNKWHALE_HOSTNAME}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${FUNKWHALE_HOSTNAME}/privkey.pem;
Luclu7's avatar
Luclu7 committed
41
42
43
    # HSTS
    add_header Strict-Transport-Security "max-age=31536000";

44
45
46
    # If you are using S3 to host your files, remember to add your S3 URL to the
    # media-src and img-src headers (e.g. img-src 'self' https://<your-S3-URL> data:)

47
    add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
48
    add_header Referrer-Policy "strict-origin-when-cross-origin";
49

50
    root ${FUNKWHALE_FRONTEND_PATH};
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    # compression settings
    gzip on;
    gzip_comp_level    5;
    gzip_min_length    256;
    gzip_proxied       any;
    gzip_vary          on;

    gzip_types
        application/javascript
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        text/x-cross-domain-policy;

    # end of compression settings
79
    location / {
80
        include /etc/nginx/funkwhale_proxy.conf;
Eliot Berriot's avatar
Eliot Berriot committed
81
        # this is needed if you have file import via upload enabled
82
        client_max_body_size ${NGINX_MAX_BODY_SIZE};
83
84
85
86
        proxy_pass   http://funkwhale-api/;
    }

    location /front/ {
87
88
89
90
        add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
        add_header Referrer-Policy "strict-origin-when-cross-origin";

        add_header X-Frame-Options "SAMEORIGIN";
Eliot Berriot's avatar
Eliot Berriot committed
91
        alias ${FUNKWHALE_FRONTEND_PATH}/;
92
93
94
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
95
    }
96
97
98
99
100
101
102
103
104
105
    location /front/embed.html {
        add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; media-src 'self' data:";
        add_header Referrer-Policy "strict-origin-when-cross-origin";

        add_header X-Frame-Options "ALLOW";
        alias ${FUNKWHALE_FRONTEND_PATH}/embed.html;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
106

107
108
109
110
111
    location /federation/ {
        include /etc/nginx/funkwhale_proxy.conf;
        proxy_pass   http://funkwhale-api/federation/;
    }

112
113
114
115
116
117
    # You can comment this if you do not plan to use the Subsonic API
    location /rest/ {
        include /etc/nginx/funkwhale_proxy.conf;
        proxy_pass   http://funkwhale-api/api/subsonic/rest/;
    }

118
    location /.well-known/ {
119
        include /etc/nginx/funkwhale_proxy.conf;
120
        proxy_pass   http://funkwhale-api/.well-known/;
121
122
    }

123
    location /media/ {
124
        alias ${MEDIA_ROOT}/;
125
    }
126

127
128
129
130
131
    location /_protected/media {
        # this is an internal location that is used to serve
        # audio files once correct permission / authentication
        # has been checked on API side
        internal;
132
        alias   ${MEDIA_ROOT};
133
    }
134

135
136
137
138
    # Comment the previous location and uncomment this one if you're storing
    # media files in a S3 bucket
    # location ~ /_protected/media/(.+) {
    #     internal;
139
140
    #     # Needed to ensure DSub auth isn't forwarded to S3/Minio, see #932
    #     proxy_set_header Authorization "";
141
142
    #     proxy_pass $1;
    # }
143

144
145
146
147
    location /_protected/music {
        # this is an internal location that is used to serve
        # audio files once correct permission / authentication
        # has been checked on API side
148
        # Set this to the same value as your MUSIC_DIRECTORY_PATH setting
149
        internal;
150
        alias   ${MUSIC_DIRECTORY_SERVE_PATH};
151
152
    }

153
    location /staticfiles/ {
154
        # django static files
155
        alias ${STATIC_ROOT}/;
156
157
    }
}