cryptpad/docs/example.nginx.conf

135 lines
5.9 KiB
Text
Raw Normal View History

# This file is included strictly as an example of how Nginx can be configured
# to work with CryptPad. This example WILL NOT WORK AS IS. For best results,
# compare the sections of this configuration file against a working CryptPad
# installation (http server by the Nodejs process). If you are using CryptPad
# in production, contact sales@cryptpad.fr
2017-03-30 09:43:20 +00:00
server {
listen 443 ssl http2;
2019-12-06 00:41:45 +00:00
# XXX These two variables
set $main_domain "your-main-domain.com";
set $sandbox_domain "your-sandbox-domain.com";
# The $api_domain and $files_domain are optional
set $api_domain "api.your-main-domain.com";
set $files_domain "files.your-main-domain.com";
server_name $main_domain $sandbox_domain;
2017-03-30 09:43:20 +00:00
ssl_certificate /home/cryptpad/.acme.sh/your-main-domain.com/fullchain.cer;
ssl_certificate_key /home/cryptpad/.acme.sh/your-main-domain.com/your-main-domain.com.key;
ssl_trusted_certificate /home/cryptpad/.acme.sh/your-main-domain.com/ca.cer;
2017-03-30 09:43:20 +00:00
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # omit SSLv3 because of POODLE
# ECDHE better than DHE (faster) ECDHE & DHE GCM better than CBC (attacks on AES) Everything better than SHA1 (deprecated)
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA';
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
# add_header X-Frame-Options "SAMEORIGIN";
2019-12-06 00:41:45 +00:00
# Insert the path to your CryptPad repository root here
2017-03-30 09:43:20 +00:00
root /home/cryptpad/cryptpad;
index index.html;
error_page 404 /customize.dist/404.html;
2017-03-30 09:43:20 +00:00
if ($args ~ ver=) {
set $cacheControl max-age=31536000;
}
# Will not set any header if it is emptystring
add_header Cache-Control $cacheControl;
2019-12-06 00:41:45 +00:00
set $styleSrc "'unsafe-inline' 'self' ${main_domain}";
set $scriptSrc "'self' ${main_domain}";
set $connectSrc "'self' https://${main_domain} wss://${main_domain} $main_domain https://${api_domain} blob:";
set $fontSrc "'self' data: ${main_domain}";
set $imgSrc "'self' data: * blob: ${main_domain}";
set $frameSrc "'self' ${sandbox_domain} blob:";
set $mediaSrc "'self' data: * blob: ${main_domain}";
set $childSrc "https://${main_domain}";
set $workerSrc "https://${main_domain}";
set $unsafe 0;
if ($uri = "/pad/inner.html") { set $unsafe 1; }
if ($uri = "/sheet/inner.html") { set $unsafe 1; }
if ($uri = "/common/onlyoffice/web-apps/apps/spreadsheeteditor/main/index.html") { set $unsafe 1; }
if ($host != sandbox.cryptpad.info) { set $unsafe 0; }
if ($unsafe) {
2019-12-06 00:41:45 +00:00
set $scriptSrc "'self' 'unsafe-eval' 'unsafe-inline' ${main_domain}";
2017-03-30 09:43:20 +00:00
}
add_header Content-Security-Policy "default-src 'none'; child-src $childSrc; worker-src $workerSrc; media-src $mediaSrc; style-src $styleSrc; script-src $scriptSrc; connect-src $connectSrc; font-src $fontSrc; img-src $imgSrc; frame-src $frameSrc;";
2017-03-30 09:43:20 +00:00
location ^~ /cryptpad_websocket {
2017-03-30 09:43:20 +00:00
proxy_pass http://localhost:3000;
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 (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
}
location ^~ /datastore/ {
alias /home/cryptpad/office.cryptpad/data/datastore;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Max-Age' 0;
add_header 'Content-Type' 'application/octet-stream; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
add_header Cache-Control max-age=0;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
try_files $uri =404;
}
2017-03-30 09:43:20 +00:00
location ^~ /customize.dist/ {
# This is needed in order to prevent infinite recursion between /customize/ and the root
}
location ^~ /customize/ {
rewrite ^/customize/(.*)$ $1 break;
try_files /customize/$uri /customize.dist/$uri;
}
location = /api/config {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
2017-05-09 09:51:32 +00:00
location ^~ /blob/ {
add_header Cache-Control max-age=31536000;
try_files $uri =404;
}
2018-07-18 14:01:27 +00:00
location ^~ /block/ {
add_header Cache-Control max-age=0;
try_files $uri =404;
}
location ^~ /datastore/ {
add_header Cache-Control max-age=0;
2017-05-09 09:51:32 +00:00
try_files $uri =404;
}
location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media|profile|contacts|todo|filepicker|debug|kanban|sheet|support|admin|notifications|teams)$ {
2017-03-30 09:43:20 +00:00
rewrite ^(.*)$ $1/ redirect;
}
try_files /www/$uri /www/$uri/index.html /customize/$uri;
}