|
| 1 | + # maximum file upload size (keep up to date when changing the corresponding site setting) |
| 2 | + client_max_body_size 10m; |
| 3 | + |
| 4 | + # path to discourse's public directory |
| 5 | + set $public __FINALPATH__/public/; |
| 6 | + |
| 7 | + # without weak etags we get zero benefit from etags on dynamically compressed content |
| 8 | + # further more etags are based on the file in nginx not sha of data |
| 9 | + # use dates, it solves the problem fine even cross server |
| 10 | + etag off; |
| 11 | + |
| 12 | + # prevent direct download of backups |
| 13 | + location ^~ __PATH__/backups/ { |
| 14 | + internal; |
| 15 | + } |
| 16 | + |
| 17 | + # bypass rails stack with a cheap 204 for favicon.ico requests |
| 18 | + location __PATH__/favicon.ico { |
| 19 | + return 204; |
| 20 | + access_log off; |
| 21 | + log_not_found off; |
| 22 | + } |
| 23 | + |
| 24 | + location __PATH__ { |
| 25 | + alias $public; |
| 26 | + add_header ETag ""; |
| 27 | + |
| 28 | + if ($scheme = http) { |
| 29 | + rewrite ^ https://$server_name$request_uri? permanent; |
| 30 | + } |
| 31 | + |
| 32 | + # auth_basic on; |
| 33 | + # auth_basic_user_file /etc/nginx/htpasswd; |
| 34 | + |
| 35 | + # Include SSOWAT user panel. |
| 36 | + include conf.d/yunohost_panel.conf.inc; |
| 37 | + |
| 38 | + |
| 39 | + location ~* (assets|plugins|uploads)/.*\.(eot|ttf|woff|woff2|ico)$ { |
| 40 | + expires 1y; |
| 41 | + add_header Cache-Control public,immutable; |
| 42 | + add_header Access-Control-Allow-Origin *; |
| 43 | + } |
| 44 | + |
| 45 | + location = __PATH__/srv/status { |
| 46 | + access_log off; |
| 47 | + log_not_found off; |
| 48 | + proxy_set_header Host $http_host; |
| 49 | + proxy_set_header X-Real-IP $remote_addr; |
| 50 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 51 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 52 | + proxy_set_header X-Forwarded-Proto https; |
| 53 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 54 | + break; |
| 55 | + } |
| 56 | + |
| 57 | + # some minimal caching here so we don't keep asking |
| 58 | + # longer term we should increas probably to 1y |
| 59 | + location ~ ^/javascripts/ { |
| 60 | + expires 1d; |
| 61 | + add_header Cache-Control public,immutable; |
| 62 | + } |
| 63 | + |
| 64 | + location ~ ^/assets/(?<asset_path>.+)$ { |
| 65 | + expires 1y; |
| 66 | + # asset pipeline enables this |
| 67 | + # brotli_static on; |
| 68 | + gzip_static on; |
| 69 | + add_header Cache-Control public,immutable; |
| 70 | + # HOOK in asset location (used for extensibility) |
| 71 | + # TODO I don't think this break is needed, it just breaks out of rewrite |
| 72 | + break; |
| 73 | + } |
| 74 | + |
| 75 | + location ~ ^/plugins/ { |
| 76 | + expires 1y; |
| 77 | + add_header Cache-Control public,immutable; |
| 78 | + } |
| 79 | + |
| 80 | + # cache emojis |
| 81 | + location ~ /images/emoji/ { |
| 82 | + expires 1y; |
| 83 | + add_header Cache-Control public,immutable; |
| 84 | + } |
| 85 | + |
| 86 | + location ~ ^/uploads/ { |
| 87 | + |
| 88 | + # NOTE: it is really annoying that we can't just define headers |
| 89 | + # at the top level and inherit. |
| 90 | + # |
| 91 | + # proxy_set_header DOES NOT inherit, by design, we must repeat it, |
| 92 | + # otherwise headers are not set correctly |
| 93 | + proxy_set_header Host $http_host; |
| 94 | + proxy_set_header X-Real-IP $remote_addr; |
| 95 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 96 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 97 | + proxy_set_header X-Forwarded-Proto https; |
| 98 | + proxy_set_header X-Sendfile-Type X-Accel-Redirect; |
| 99 | + proxy_set_header X-Accel-Mapping $public/=/downloads/; |
| 100 | + expires 1y; |
| 101 | + add_header Cache-Control public,immutable; |
| 102 | + |
| 103 | + ## optional upload anti-hotlinking rules |
| 104 | + #valid_referers none blocked mysite.com *.mysite.com; |
| 105 | + #if ($invalid_referer) { return 403; } |
| 106 | + |
| 107 | + # custom CSS |
| 108 | + location ~ /stylesheet-cache/ { |
| 109 | + try_files $uri =404; |
| 110 | + } |
| 111 | + # this allows us to bypass rails |
| 112 | + location ~* \.(gif|png|jpg|jpeg|bmp|tif|tiff|svg|ico|webp)$ { |
| 113 | + try_files $uri =404; |
| 114 | + } |
| 115 | + # thumbnails & optimized images |
| 116 | + location ~ /_?optimized/ { |
| 117 | + try_files $uri =404; |
| 118 | + } |
| 119 | + |
| 120 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 121 | + break; |
| 122 | + } |
| 123 | + |
| 124 | + location ~ ^/admin/backups/ { |
| 125 | + proxy_set_header Host $http_host; |
| 126 | + proxy_set_header X-Real-IP $remote_addr; |
| 127 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 128 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 129 | + proxy_set_header X-Forwarded-Proto https; |
| 130 | + proxy_set_header X-Sendfile-Type X-Accel-Redirect; |
| 131 | + proxy_set_header X-Accel-Mapping $public/=/downloads/; |
| 132 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 133 | + break; |
| 134 | + } |
| 135 | + |
| 136 | + # This big block is needed so we can selectively enable |
| 137 | + # acceleration for backups and avatars |
| 138 | + # see note about repetition above |
| 139 | + location ~ ^/(letter_avatar/|user_avatar|highlight-js|stylesheets|favicon/proxied|service-worker) { |
| 140 | + proxy_set_header Host $http_host; |
| 141 | + proxy_set_header X-Real-IP $remote_addr; |
| 142 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 143 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 144 | + proxy_set_header X-Forwarded-Proto https; |
| 145 | + |
| 146 | + # if Set-Cookie is in the response nothing gets cached |
| 147 | + # this is double bad cause we are not passing last modified in |
| 148 | + proxy_ignore_headers "Set-Cookie"; |
| 149 | + proxy_hide_header "Set-Cookie"; |
| 150 | + |
| 151 | + # note x-accel-redirect can not be used with proxy_cache |
| 152 | +# proxy_cache one; |
| 153 | + proxy_cache_valid 200 301 302 7d; |
| 154 | + proxy_cache_valid any 1m; |
| 155 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 156 | + break; |
| 157 | + } |
| 158 | + |
| 159 | +# location /letter_avatar_proxy/ { |
| 160 | +# # Don't send any client headers to the avatars service |
| 161 | +# proxy_method GET; |
| 162 | +# proxy_pass_request_headers off; |
| 163 | +# proxy_pass_request_body off; |
| 164 | +# |
| 165 | +# # Don't let cookies interrupt caching, and don't pass them to the |
| 166 | +# # client |
| 167 | +# proxy_ignore_headers "Set-Cookie"; |
| 168 | +# proxy_hide_header "Set-Cookie"; |
| 169 | +# |
| 170 | +# proxy_cache one; |
| 171 | +# proxy_cache_key $uri; |
| 172 | +# proxy_cache_valid 200 7d; |
| 173 | +# proxy_cache_valid 404 1m; |
| 174 | +# proxy_set_header Connection ""; |
| 175 | +# |
| 176 | +# proxy_pass https://avatars.discourse.org/; |
| 177 | +# break; |
| 178 | +# } |
| 179 | + |
| 180 | + # we need buffering off for message bus |
| 181 | + location __PATH__/message-bus/ { |
| 182 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 183 | + proxy_set_header Host $http_host; |
| 184 | + proxy_set_header X-Real-IP $remote_addr; |
| 185 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 186 | + proxy_set_header X-Forwarded-Proto https; |
| 187 | + proxy_http_version 1.1; |
| 188 | + proxy_buffering off; |
| 189 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 190 | + break; |
| 191 | + } |
| 192 | + |
| 193 | + # this means every file in public is tried first |
| 194 | + try_files $uri @__NAME__; |
| 195 | + } |
| 196 | + |
| 197 | + location __PATH__/downloads/ { |
| 198 | + internal; |
| 199 | + alias $public/; |
| 200 | + } |
| 201 | + |
| 202 | + location @__NAME__ { |
| 203 | + add_header Referrer-Policy 'no-referrer-when-downgrade'; |
| 204 | + proxy_set_header Host $http_host; |
| 205 | + proxy_set_header X-Request-Start "t=${msec}"; |
| 206 | + proxy_set_header X-Real-IP $remote_addr; |
| 207 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 208 | + proxy_set_header X-Forwarded-Proto https; |
| 209 | + proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock; |
| 210 | +} |
0 commit comments