nixos-configs/configurations/nos/modules/docker/nextcloud/nginx.conf

197 lines
6.2 KiB
Nginx Configuration File
Raw Normal View History

user www-data;
worker_processes 1;
2024-02-23 00:34:43 -05:00
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
2024-02-23 00:34:43 -05:00
events {
worker_connections 1024;
2024-02-23 00:34:43 -05:00
}
http {
upstream backend {
server app-server:9000;
#server unix:/var/run/php/php7.4-fpm.sock;
2024-02-23 00:34:43 -05:00
}
# Set the `immutable` cache control options only for assets with a cache busting `v` argument
map $arg_v $asset_immutable {
"" "";
default "immutable";
2024-02-23 00:34:43 -05:00
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
2024-02-23 00:34:43 -05:00
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
2024-02-23 00:34:43 -05:00
access_log /var/log/nginx/access.log main;
2024-02-23 00:34:43 -05:00
sendfile on;
2024-02-23 00:34:43 -05:00
#tcp_nopush on;
keepalive_timeout 65;
2024-02-23 00:34:43 -05:00
map $http_host $this_host {
"" $host;
default $http_host;
}
map $http_x_forwarded_proto $the_scheme {
default $http_x_forwarded_proto;
"" $scheme;
}
map $http_x_forwarded_host $the_host {
default $http_x_forwarded_host;
"" $this_host;
2024-02-23 00:34:43 -05:00
}
server {
listen 80;
# The below allows for being behind a reverse proxy and allowing the Nextcloud app to connect
2024-02-23 00:34:43 -05:00
server_tokens off;
# Add headers to serve security related headers
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "noindex, nofollow" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
2024-02-23 00:34:43 -05:00
fastcgi_hide_header X-Powered-By;
root /var/www/html;
client_max_body_size 10G; # 0=unlimited - set max upload size
fastcgi_buffers 64 4K;
client_body_buffer_size 512k;
gzip off;
index index.php index.html /index.php$request_uri;
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
if ( $http_user_agent ~ ^DavClnt ) {
2024-02-23 00:34:43 -05:00
return 302 /remote.php/webdav/$is_args$args;
}
}
location ^~ /.well-known {
location = /.well-known/carddav {
return 301 /remote.php/dav/;
}
location = /.well-known/caldav {
return 301 /remote.php/dav/;
}
2024-02-23 00:34:43 -05:00
#location = /.well-known/webfinger { return 301 /index.php/.well-known/webfinger/; }
#location = /.well-known/nodeinfo { return 301 /index.php/.well-known/nodeinfo/; }}
location /.well-known/acme-challenge {
try_files $uri $uri/ =404;
}
location /.well-known/pki-validation {
try_files $uri $uri/ =404;
}
2024-02-23 00:34:43 -05:00
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
return 301 /index.php$request_uri;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) {
return 404;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
return 404;
}
2024-02-23 00:34:43 -05:00
location ~* ^/ds-vpath/ {
rewrite /ds-vpath/(.*) /$1 break;
proxy_pass http://onlyoffice-document-server;
proxy_redirect off;
2024-02-23 00:34:43 -05:00
client_max_body_size 10G;
2024-02-23 00:34:43 -05:00
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
2024-02-23 00:34:43 -05:00
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $the_host/ds-vpath;
proxy_set_header X-Forwarded-Proto $the_scheme;
2024-02-23 00:34:43 -05:00
}
location ~ \.php(?:$|/) {
# Required for legacy support
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS off;
fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
fastcgi_param front_controller_active true;
fastcgi_pass backend;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_max_temp_file_size 0;
}
location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
2024-02-23 00:34:43 -05:00
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463, $asset_immutable";
access_log off; # Optional: Don't log access to assets
2024-02-23 00:34:43 -05:00
location ~ \.wasm$ {
default_type application/wasm;
}
location ~ \.mjs$ {
default_type text/javascript;
}
2024-02-23 00:34:43 -05:00
}
2024-02-23 00:34:43 -05:00
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
2024-02-23 00:34:43 -05:00
}
# Rule borrowed from `.htaccess`
location /remote {
return 301 /remote.php$request_uri;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}
}