Fresh repo without sensitive data.
This commit is contained in:
commit
9003080a64
44 changed files with 2039 additions and 0 deletions
286
services/nginx.nix
Normal file
286
services/nginx.nix
Normal file
|
@ -0,0 +1,286 @@
|
|||
##############################################################################################
|
||||
# Includes: #
|
||||
# - Nginx + SSL config #
|
||||
# - Gitea #
|
||||
# - Nextcloud #
|
||||
# - Heavily based on: https://gist.github.com/schneefux/22b75d2bd3e4e754ba1684f1d1e93271 #
|
||||
# - Mail ssl root #
|
||||
##############################################################################################
|
||||
|
||||
{ conf, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
gitpkgs = import /nixpkgs/default.nix {};
|
||||
in {
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
recommendedGzipSettings = true;
|
||||
recommendedOptimisation = true;
|
||||
recommendedProxySettings = true;
|
||||
sslCiphers = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256";
|
||||
virtualHosts = {
|
||||
"ophanim.de" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = "/var/www";
|
||||
};
|
||||
"builder.ophanim.de" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
extraConfig = ''
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3001;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header REMOTE_ADDR $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
'';
|
||||
};
|
||||
"mail.ophanim.de" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = "/var/www";
|
||||
};
|
||||
"storage.ophanim.de" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = "${gitpkgs.nextcloud}";
|
||||
locations = {
|
||||
"/robots.txt" = {
|
||||
extraConfig = ''
|
||||
allow all;
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
'';
|
||||
};
|
||||
|
||||
"~ ^/(?:\.htaccess|config|db_structure\.xml|README)" = {
|
||||
extraConfig = "deny all;";
|
||||
};
|
||||
|
||||
"/" = {
|
||||
extraConfig = ''
|
||||
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
|
||||
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
|
||||
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
|
||||
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
|
||||
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
'';
|
||||
};
|
||||
|
||||
"~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/)" = {
|
||||
extraConfig = ''
|
||||
include ${pkgs.nginx}/conf/uwsgi_params;
|
||||
uwsgi_modifier1 14;
|
||||
uwsgi_hide_header X-Frame-Options;
|
||||
uwsgi_hide_header X-XSS-Protection;
|
||||
uwsgi_hide_header X-Content-Type-Options;
|
||||
uwsgi_hide_header X-Robots-Tag;
|
||||
uwsgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
|
||||
uwsgi_pass unix:/run/uwsgi/php.sock;
|
||||
'';
|
||||
};
|
||||
|
||||
"~* \.(?:css|js)$" = {
|
||||
extraConfig = ''
|
||||
add_header Cache-Control "public, max-age=7200";
|
||||
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-Frame-Options "SAMEORIGIN";
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Robots-Tag none;
|
||||
add_header X-Download-Options noopen;
|
||||
add_header X-Permitted-Cross-Domain-Policies none;
|
||||
access_log off;
|
||||
'';
|
||||
};
|
||||
|
||||
"~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$" = {
|
||||
extraConfig = ''
|
||||
access_log off;
|
||||
'';
|
||||
};
|
||||
|
||||
"^~ /data" = {
|
||||
extraConfig = ''
|
||||
internal;
|
||||
'';
|
||||
};
|
||||
|
||||
"^~ /apps" = {
|
||||
extraConfig = ''
|
||||
alias /var/lib/nextcloud/apps;
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
### Settings for new nextcloud module.... does not work yet???
|
||||
# locations = {
|
||||
# "= /robots.txt" = {
|
||||
# priority = 100;
|
||||
# extraConfig = ''
|
||||
# allow all;
|
||||
# log_not_found off;
|
||||
# access_log off;
|
||||
# '';
|
||||
# };
|
||||
# "/" = {
|
||||
# priority = 200;
|
||||
# extraConfig = "rewrite ^ /index.php$uri;";
|
||||
# };
|
||||
# "~ ^/store-apps" = {
|
||||
# priority = 201;
|
||||
# extraConfig = "root /var/lib/nextcloud;";
|
||||
# };
|
||||
# "= /.well-known/carddav" = {
|
||||
# priority = 210;
|
||||
# extraConfig = "return 301 $scheme://$host/remote.php/dav;";
|
||||
# };
|
||||
# "= /.well-known/caldav" = {
|
||||
# priority = 210;
|
||||
# extraConfig = "return 301 $scheme://$host/remote.php/dav;";
|
||||
# };
|
||||
# "~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/" = {
|
||||
# priority = 300;
|
||||
# extraConfig = "deny all;";
|
||||
# };
|
||||
# "~ ^/(?:\\.|autotest|occ|issue|indie|db_|console)" = {
|
||||
# priority = 300;
|
||||
# extraConfig = "deny all;";
|
||||
# };
|
||||
# "~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\\.php(?:$|/)" = {
|
||||
# priority = 500;
|
||||
# extraConfig = ''
|
||||
# include ${pkgs.nginxMainline}/conf/fastcgi.conf;
|
||||
# fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
||||
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
# fastcgi_param HTTPS on;
|
||||
# fastcgi_param modHeadersAvailable true;
|
||||
# fastcgi_param front_controller_active true;
|
||||
# fastcgi_pass unix:/run/phpfpm/nextcloud;
|
||||
# fastcgi_intercept_errors on;
|
||||
# fastcgi_request_buffering off;
|
||||
# fastcgi_read_timeout 120s;
|
||||
# '';
|
||||
# };
|
||||
# "~ ^/(?:updater|ocs-provider)(?:$|/)".extraConfig = ''
|
||||
# try_files $uri/ =404;
|
||||
# index index.php;
|
||||
# '';
|
||||
# "~ \\.(?:css|js|woff|svg|gif)$".extraConfig = ''
|
||||
# try_files $uri /index.php$uri$is_args$args;
|
||||
# add_header Cache-Control "public, max-age=15778463";
|
||||
# add_header X-Content-Type-Options nosniff;
|
||||
# add_header X-XSS-Protection "1; mode=block";
|
||||
# add_header X-Robots-Tag none;
|
||||
# add_header X-Download-Options noopen;
|
||||
# add_header X-Permitted-Cross-Domain-Policies none;
|
||||
# access_log off;
|
||||
# '';
|
||||
# "~ \\.(?:png|html|ttf|ico|jpg|jpeg)$".extraConfig = ''
|
||||
# try_files $uri /index.php$uri$is_args$args;
|
||||
# access_log off;
|
||||
# '';
|
||||
# };
|
||||
# extraConfig = ''
|
||||
# add_header X-Content-Type-Options nosniff;
|
||||
# add_header X-XSS-Protection "1; mode=block";
|
||||
# add_header X-Robots-Tag none;
|
||||
# add_header X-Download-Options noopen;
|
||||
# add_header X-Permitted-Cross-Domain-Policies none;
|
||||
# error_page 403 /core/templates/403.php;
|
||||
# error_page 404 /core/templates/404.php;
|
||||
# client_max_body_size 1024M;
|
||||
# fastcgi_buffers 64 4K;
|
||||
# gzip on;
|
||||
# gzip_vary on;
|
||||
# gzip_comp_level 4;
|
||||
# gzip_min_length 256;
|
||||
# gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
|
||||
# gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml 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;
|
||||
# '';
|
||||
};
|
||||
"git.ophanim.de" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = "/var/lib/gitea/public";
|
||||
extraConfig = ''
|
||||
location / {
|
||||
try_files maintain.html $uri $uri/index.html @node;
|
||||
}
|
||||
|
||||
location @node {
|
||||
client_max_body_size 0;
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Ssl on;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_max_temp_file_size 0;
|
||||
proxy_redirect off;
|
||||
proxy_read_timeout 120;
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Nextcloud system cron
|
||||
users.users.nginx.useDefaultShell = true;
|
||||
systemd.services.nextcloudcron = {
|
||||
description = "Nextcloud cron";
|
||||
after = [ "network.target" ];
|
||||
script = ''
|
||||
${pkgs.php}/bin/php ${gitpkgs.nextcloud}/cron.php
|
||||
${gitpkgs.nextcloud-news-updater}/bin/nextcloud-news-updater -t 2 -i 30 --mode singlerun ${gitpkgs.nextcloud}
|
||||
'';
|
||||
environment = { NEXTCLOUD_CONFIG_DIR = "/var/lib/nextcloud/config"; };
|
||||
serviceConfig.User = "nginx";
|
||||
};
|
||||
systemd.timers.nextcloudcron = {
|
||||
enable = true;
|
||||
description = "Nextcloud cron timer";
|
||||
wantedBy = [ "timers.target" ];
|
||||
partOf = [ "Nextcloudcron.service" ];
|
||||
timerConfig = {
|
||||
RandomizedDelaySec = "5min";
|
||||
OnCalendar = "*-*-* *:00,30:00"; # every 1/2h
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
|
||||
services.uwsgi = {
|
||||
enable = true;
|
||||
user = "nginx";
|
||||
group = "nginx";
|
||||
instance = {
|
||||
type = "emperor";
|
||||
vassals = {
|
||||
php = {
|
||||
type = "normal";
|
||||
socket = "/run/uwsgi/php.sock";
|
||||
master = true;
|
||||
vacuum = true;
|
||||
|
||||
processes = 16;
|
||||
cheaper = 1;
|
||||
php-sapi-name = "apache"; # opcode caching tweak
|
||||
|
||||
php-allowed-ext = [ ".php" ".inc" ];
|
||||
socket-modifier1 = 14;
|
||||
php-index = "index.php";
|
||||
|
||||
php-set = "date.timezone=Europe/Berlin";
|
||||
env = [
|
||||
"NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config"
|
||||
];
|
||||
plugins = [ "php" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
plugins = [ "php" ];
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue