diff options
Diffstat (limited to 'roles/nextcloud')
-rw-r--r-- | roles/nextcloud/files/etc/cron.d/nextcloud | 2 | ||||
-rw-r--r-- | roles/nextcloud/files/etc/ldap/ldap.conf | 4 | ||||
-rw-r--r-- | roles/nextcloud/files/etc/logrotate.d/nextcloud | 9 | ||||
-rw-r--r-- | roles/nextcloud/files/etc/nginx/sites-available/nextcloud | 76 | ||||
-rw-r--r-- | roles/nextcloud/files/etc/php/fpm/pool.d/nextcloud.conf | 24 | ||||
-rw-r--r-- | roles/nextcloud/handlers/main.yml | 7 | ||||
-rw-r--r-- | roles/nextcloud/tasks/main.yml | 140 |
7 files changed, 202 insertions, 60 deletions
diff --git a/roles/nextcloud/files/etc/cron.d/nextcloud b/roles/nextcloud/files/etc/cron.d/nextcloud index 8bd7d86..3c4aac0 100644 --- a/roles/nextcloud/files/etc/cron.d/nextcloud +++ b/roles/nextcloud/files/etc/cron.d/nextcloud @@ -1,2 +1,2 @@ MAILTO=root -*/15 * * * * www-data php -f /var/www/nextcloud/cron.php +*/5 * * * * _nextcloud php -f /usr/local/share/nextcloud/cron.php diff --git a/roles/nextcloud/files/etc/ldap/ldap.conf b/roles/nextcloud/files/etc/ldap/ldap.conf index 5f388f1..b4ebe34 100644 --- a/roles/nextcloud/files/etc/ldap/ldap.conf +++ b/roles/nextcloud/files/etc/ldap/ldap.conf @@ -6,5 +6,5 @@ # This file should be world readable but not world writable. # TLS certificates (needed for GnuTLS) -TLS_CACERT /etc/ldap/ssl/ldap.fripost.org.pem -TLS_REQCERT hard +TLS_CACERT /etc/ldap/ssl/ldap.fripost.org.pem +TLS_REQCERT hard diff --git a/roles/nextcloud/files/etc/logrotate.d/nextcloud b/roles/nextcloud/files/etc/logrotate.d/nextcloud new file mode 100644 index 0000000..b8dd232 --- /dev/null +++ b/roles/nextcloud/files/etc/logrotate.d/nextcloud @@ -0,0 +1,9 @@ +/var/log/nextcloud/*.log { + daily + missingok + rotate 7 + compress + delaycompress + notifempty + create 0640 _nextcloud adm +} diff --git a/roles/nextcloud/files/etc/nginx/sites-available/nextcloud b/roles/nextcloud/files/etc/nginx/sites-available/nextcloud index 9e5e9b0..f1f4dcc 100644 --- a/roles/nextcloud/files/etc/nginx/sites-available/nextcloud +++ b/roles/nextcloud/files/etc/nginx/sites-available/nextcloud @@ -4,10 +4,10 @@ server { server_name cloud.fripost.org; - include snippets/acme-challenge.conf; + include /etc/lacme/nginx.conf; - access_log /var/log/nginx/cloud.access.log; - error_log /var/log/nginx/cloud.error.log info; + access_log /var/log/nginx/cloud.access.log; + error_log /var/log/nginx/cloud.error.log info; location / { return 301 https://$host$request_uri; @@ -20,10 +20,10 @@ server { server_name cloud.fripost.org; - root /var/www/nextcloud/; + root /usr/local/share/nextcloud; include snippets/headers.conf; - add_header X-Robots-Tag none; + add_header X-Robots-Tag "noindex, nofollow"; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; @@ -32,17 +32,26 @@ server { ssl_certificate_key ssl/cloud.fripost.org.key; include snippets/cloud.fripost.org.hpkp-hdr; + include mime.types; + types { + text/javascript js mjs; + application/wasm wasm; + } + location = /robots.txt { allow all; log_not_found off; access_log off; } - access_log /var/log/nginx/cloud.access.log; - error_log /var/log/nginx/cloud.error.log info; + access_log /var/log/nginx/cloud.access.log; + error_log /var/log/nginx/cloud.error.log info; - location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; } - location = /.well-known/caldav { return 301 $scheme://$host/remote.php/dav; } + index index.php index.html /index.php$request_uri; + + location = /.well-known/carddav { return 301 /remote.php/dav; } + location = /.well-known/caldav { return 301 /remote.php/dav; } + location ^~ /.well-known/ { return 301 /index.php$request_uri; } # set max upload size client_max_body_size 512M; @@ -57,39 +66,44 @@ server { 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; - error_page 403 /core/templates/403.php; - error_page 404 /core/templates/404.php; - - location = / { return 303 $scheme://$host/apps/files/; } - location / { rewrite ^ /index.php$uri last; } + location = / { return 303 /apps/files/; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { internal; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { internal; } - location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) { - fastcgi_split_path_info ^(.+\.php)(/.*)$; + location ~ \.php(?:$|/) { + # Required for legacy support + rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /index.php$request_uri; + include snippets/fastcgi-php.conf; fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; + fastcgi_intercept_errors on; fastcgi_request_buffering off; - fastcgi_param PHP_VALUE "upload_max_filesize=512M - post_max_size=512M - memory_limit=512M"; - fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root:/mnt/nextcloud-data:/etc/nextcloud:/usr/share/php:/tmp:/dev"; + fastcgi_pass unix:/run/php/php8.2-fpm@nextcloud.sock; } - location ~ ^/(?:updater|ocs-provider)(?:$|/) { - try_files $uri/ =404; - index index.php; + location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ { + try_files $uri /index.php$uri$is_args$args; } - - location ~* \.(?:css|js|woff|svg|gif)$ { + location ~ \.woff2?$ { + try_files $uri /index.php$request_uri; + expires 7d; + } + location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ { try_files $uri /index.php$uri$is_args$args; - expires 30d; } - location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ { - try_files $uri /index.php$uri$is_args$args; + location /remote { + return 301 /remote.php$request_uri; + } + + location / { + try_files $uri $uri/ /index.php$request_uri; + } + + location = /core/img/favicon.ico { + alias /var/www/nextcloud/fripost.ico; } } @@ -101,10 +115,10 @@ server { server_name www.cloud.fripost.org; - include snippets/acme-challenge.conf; + include /etc/lacme/nginx.conf; - access_log /var/log/nginx/cloud.access.log; - error_log /var/log/nginx/cloud.error.log info; + access_log /var/log/nginx/cloud.access.log; + error_log /var/log/nginx/cloud.error.log info; location / { return 301 https://cloud.fripost.org$request_uri; diff --git a/roles/nextcloud/files/etc/php/fpm/pool.d/nextcloud.conf b/roles/nextcloud/files/etc/php/fpm/pool.d/nextcloud.conf new file mode 100644 index 0000000..898ce60 --- /dev/null +++ b/roles/nextcloud/files/etc/php/fpm/pool.d/nextcloud.conf @@ -0,0 +1,24 @@ +[nextcloud] +user = _nextcloud +group = nogroup +listen = /run/php/php8.2-fpm@nextcloud.sock +listen.owner = www-data +listen.group = www-data +listen.mode = 0600 +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 + +php_value[upload_max_filesize] = 512M +php_value[post_max_size] = 512M +php_value[memory_limit] = 512M + +php_admin_value[open_basedir] = /usr/local/share/nextcloud:/var/www/nextcloud:/mnt/nextcloud-data:/etc/nextcloud:/var/cache/nextcloud:/var/log/nextcloud:/usr/share/php:/tmp:/dev + +env[HOSTNAME] = $HOSTNAME +env[PATH] = /usr/bin:/bin +env[TMP] = /tmp +env[TMPDIR] = /tmp +env[TEMP] = /tmp diff --git a/roles/nextcloud/handlers/main.yml b/roles/nextcloud/handlers/main.yml index 6552940..a14d6e1 100644 --- a/roles/nextcloud/handlers/main.yml +++ b/roles/nextcloud/handlers/main.yml @@ -1,6 +1,9 @@ --- -- name: Restart php7.0-fpm - service: name=php7.0-fpm state=restarted +- name: Restart php8.2-fpm + service: name=php8.2-fpm state=restarted + +- name: Restart Redis + service: name=redis-server state=restarted - name: Restart Nginx service: name=nginx state=restarted diff --git a/roles/nextcloud/tasks/main.yml b/roles/nextcloud/tasks/main.yml index 09554e0..14bc02c 100644 --- a/roles/nextcloud/tasks/main.yml +++ b/roles/nextcloud/tasks/main.yml @@ -3,12 +3,13 @@ vars: packages: - php-cli + - php-bcmath - php-fpm - php-apcu - php-gd + - php-gmp - php-imagick - php-mbstring - - php-mcrypt - php-xml - php-curl - php-intl @@ -16,41 +17,54 @@ - php-mysql - php-zip - php-json + - php-gmp -- name: Configure PHP 7.0 Zend opcache - lineinfile: dest=/etc/php/7.0/fpm/php.ini +- name: Configure PHP 8.2 Zend opcache + lineinfile: dest=/etc/php/8.2/fpm/php.ini regexp='^;?{{ item.var }}\\s*=' line="{{ item.var }} = {{ item.value }}" owner=root group=root mode=0644 with_items: - - { var: opcache.enable, value: 1 } - - { var: opcache.enable_cli, value: 1 } - - { var: opcache.memory_consumption, value: 128 } - - { var: opcache.interned_strings_buffer, value: 8 } - - { var: opcache.max_accelerated_files, value: 10000 } - - { var: opcache.revalidate_freq, value: 1 } - - { var: opcache.fast_shutdown, value: 1 } + - { var: opcache.memory_consumption, value: 512 } + - { var: opcache.revalidate_freq, value: 180 } + - { var: opcache.interned_strings_buffer, value: 12 } notify: - - Restart php7.0-fpm + - Restart php8.2-fpm -- name: Configure PHP 7.0 pool environment - lineinfile: dest=/etc/php/7.0/fpm/pool.d/www.conf - regexp='^;?env\[{{ item.var }}\]\\s*=' - line="env[{{ item.var }}] = {{ item.value }}" +- name: Configure PHP 8.2 CLI + lineinfile: dest=/etc/php/8.2/cli/php.ini + regexp='^;?{{ item.var }}\\s*=' + line="{{ item.var }} = {{ item.value }}" owner=root group=root mode=0644 with_items: - - { var: HOSTNAME, value: "$HOSTNAME" } - - { var: PATH, value: "/usr/bin:/bin" } - - { var: TMP, value: "/tmp" } - - { var: TMPDIR, value: "/tmp" } - - { var: TEMP, value: "/tmp" } + - { var: apc.enable_cli, value: 1 } + +- name: Create '_nextcloud' user + user: name=_nextcloud system=yes + group=nogroup + createhome=no + home=/nonexistent + shell=/usr/sbin/nologin + password=! + state=present + +- name: Delete PHP 8.2 FPM's www pool + file: path=/etc/php/8.2/fpm/pool.d/www.conf state=absent + notify: + - Restart php8.2-fpm + +- name: Configure PHP 8.2 FPM's nextcloud pool + copy: src=etc/php/fpm/pool.d/nextcloud.conf + dest=/etc/php/8.2/fpm/pool.d/nextcloud.conf + owner=root group=root + mode=0644 notify: - - Restart php7.0-fpm + - Restart php8.2-fpm -- name: Start php7.0-fpm - service: name=php7.0-fpm state=started +- name: Start php8.2-fpm + service: name=php8.2-fpm state=started - name: Copy /etc/cron.d/nextcloud copy: src=etc/cron.d/nextcloud @@ -103,6 +117,84 @@ - genkey - import_tasks: ldap.yml - when: "'LDAP-provider' not in group_names" + when: "'LDAP_provider' not in group_names" tags: - ldap + +# Note: intentionally don't set an owner/group as we don't want to set +# ownership unless the path is a mountpoint. The service will fail +# unless the data directory is mounted and accessible, and that's what +# we want. +- name: Create directory /mnt/nextcloud-data + file: path=/mnt/nextcloud-data + state=directory + mode=0700 + +- name: Create directory /var/www/nextcloud + file: path=/var/www/nextcloud + state=directory + owner=root group=root + mode=0755 + +# Note: Nextcloud doesn't like symlinked apps +# * https://github.com/nextcloud/server/issues/10437 +# * https://github.com/nextcloud/server/issues/13556 +- name: Create directory /var/www/nextcloud/apps + file: path=/var/www/nextcloud/apps + state=directory + owner=_nextcloud group=nogroup + mode=0755 + +- name: Create directory /var/log/nextcloud + file: path=/var/log/nextcloud + state=directory + owner=_nextcloud group=adm + mode=0750 + +- name: Create directory /var/cache/nextcloud + file: path=/var/cache/nextcloud + state=directory + owner=_nextcloud group=nogroup + mode=0700 + +- name: Copy Nextcloud logrotate snippet + copy: src=etc/logrotate.d/nextcloud + dest=/etc/logrotate.d/nextcloud + owner=root group=root + mode=0644 + tags: + - logrotate + +- name: Install redis-server + apt: pkg={{ packages }} + vars: + packages: + - php-redis + - redis-server + +- name: Configure Redis + lineinfile: dest=/etc/redis/redis.conf + regexp='^#?\\s*{{ item.var }}\\s+' + line="{{ item.var }} {{ item.value }}" + owner=redis group=redis + mode=0640 + with_items: + - { var: port, value: 0 } + - { var: unixsocket, value: /run/redis/redis-server.sock } + - { var: unixsocketperm, value: 660 } + notify: + - Restart Redis + +- name: Start redis-server + service: name=redis-server state=started + +- name: Add '_nextcloud' user to 'redis' group + user: name=_nextcloud groups=redis append=yes + notify: + - Restart php8.2-fpm + +- name: Install other Nextcloud dependencies + apt: pkg={{ packages }} + vars: + packages: + - libmagickcore-6.q16-6-extra |