From 0bfbe0e49f7fc77abfe7bb5d92c72dbdf6742204 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 12 May 2020 15:36:28 +0200 Subject: Nextcloud: Better separation between code/data/logs/cache. Also, update baseline to Debian 10 (codename Buster) and deploy a local Redis instance for Transactional File Locking https://docs.nextcloud.com/server/18/admin_manual/configuration_server/caching_configuration.html#id2 --- roles/nextcloud/files/etc/cron.d/nextcloud | 2 +- .../files/etc/nginx/sites-available/nextcloud | 26 ++++--- roles/nextcloud/handlers/main.yml | 7 +- roles/nextcloud/tasks/main.yml | 90 ++++++++++++++++++---- 4 files changed, 95 insertions(+), 30 deletions(-) diff --git a/roles/nextcloud/files/etc/cron.d/nextcloud b/roles/nextcloud/files/etc/cron.d/nextcloud index 8bd7d86..681cd43 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 * * * * www-data php -f /usr/local/share/nextcloud/cron.php diff --git a/roles/nextcloud/files/etc/nginx/sites-available/nextcloud b/roles/nextcloud/files/etc/nginx/sites-available/nextcloud index 9e5e9b0..d748dc9 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,7 +20,7 @@ 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; @@ -38,8 +38,8 @@ server { 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; } @@ -67,15 +67,15 @@ server { 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)(/.*)$; 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_param PHP_ADMIN_VALUE "open_basedir=$document_root:/var/www/nextcloud:/mnt/nextcloud-data:/etc/nextcloud:/var/cache/nextcloud:/var/log/nextcloud:/usr/share/php:/tmp:/dev"; } location ~ ^/(?:updater|ocs-provider)(?:$|/) { @@ -91,6 +91,10 @@ server { location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$uri$is_args$args; } + + location = /core/img/favicon.ico { + alias /var/www/nextcloud/fripost.ico; + } } server { @@ -101,10 +105,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/handlers/main.yml b/roles/nextcloud/handlers/main.yml index 6552940..1e48524 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 php7.3-fpm + service: name=php7.3-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..86b505b 100644 --- a/roles/nextcloud/tasks/main.yml +++ b/roles/nextcloud/tasks/main.yml @@ -8,7 +8,6 @@ - php-gd - php-imagick - php-mbstring - - php-mcrypt - php-xml - php-curl - php-intl @@ -16,26 +15,22 @@ - 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 7.3 Zend opcache + lineinfile: dest=/etc/php/7.3/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 } notify: - - Restart php7.0-fpm + - Restart php7.3-fpm -- name: Configure PHP 7.0 pool environment - lineinfile: dest=/etc/php/7.0/fpm/pool.d/www.conf +- name: Configure PHP 7.3 pool environment + lineinfile: dest=/etc/php/7.3/fpm/pool.d/www.conf regexp='^;?env\[{{ item.var }}\]\\s*=' line="env[{{ item.var }}] = {{ item.value }}" owner=root group=root @@ -47,10 +42,10 @@ - { var: TMPDIR, value: "/tmp" } - { var: TEMP, value: "/tmp" } notify: - - Restart php7.0-fpm + - Restart php7.3-fpm -- name: Start php7.0-fpm - service: name=php7.0-fpm state=started +- name: Start php7.3-fpm + service: name=php7.3-fpm state=started - name: Copy /etc/cron.d/nextcloud copy: src=etc/cron.d/nextcloud @@ -106,3 +101,66 @@ when: "'LDAP-provider' not in group_names" tags: - ldap + +- 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=www-data group=www-data + mode=0755 + +- name: Create directory /var/log/nextcloud + file: path=/var/log/nextcloud + state=directory + owner=www-data group=adm + mode=0750 + +- name: Create directory /var/cache/nextcloud + file: path=/var/cache/nextcloud + state=directory + owner=www-data group=www-data + 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='^#?{{ 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: 770 } + notify: + - Restart Redis + +- name: Start redis-server + service: name=redis-server state=started + +- name: Add 'www-data' to the group 'redis' + user: name=www-data groups=redis append=yes + notify: + - Restart php7.3-fpm -- cgit v1.2.3