Nextcloud. Centos 8. Установка Nextcloud 23

Материал из Wiki
Перейти к навигации Перейти к поиску


Установка

yum -y update

yum -y install mariadb mariadb-server

systemctl start mariadb

systemctl enable mariadb

mysql_secure_installation

mysql -u root -p

CREATE DATABASE nextcloud;

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'PassWord';

FLUSH PRIVILEGES;

\q

dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

dnf module enable -y php:remi-8.2

yum -y install php php-pear php-mbstring php-mysqli php-zip php-xml php-mbstring php-gd php-fpm

yum install -y nginx

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.ORIG

nano /etc/nginx/nginx.conf

user nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
   worker_connections  2048;
   use epoll;
}
http {
   include       /etc/nginx/mime.types;
   default_type  application/octet-stream;
   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
   access_log  /var/log/nginx/access.log  main;
   sendfile        on;
   #tcp_nopush     on;
   keepalive_timeout  65;
   #gzip  on;
   proxy_connect_timeout 600;
   proxy_send_timeout 600;
   proxy_read_timeout 600;
   send_timeout 600;
   client_max_body_size 128m;
   gzip_buffers 16 8k;
   gzip_http_version 1.1;
   gzip_min_length 10;
   gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
   gzip_vary on;
   gzip_proxied any;
   gzip_disable msie6;
   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/vhosts/*.conf;
}

nano /etc/php-fpm.d/www.conf

...
listen = 127.0.0.1:9000
...

wget https://download.nextcloud.com/server/releases/nextcloud-27.0.0.zip

unzip nextcloud-27.0.0.zip -d /var/www/

mv /var/www/nextcloud/ /var/www/cloud/

chown -R apache:apache /var/www/cloud/

Настройка

Вариант 1. Доступ HTTP по локальному адресу в локальной сети

nano /etc/nginx/conf.d/default.conf

server {
       listen 80;
       server_name cloud.domain123.ru;
       root /var/www/cloud;
       add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
       client_max_body_size 10G;
       fastcgi_buffers 64 4K;
       rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
       rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
       rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
       index index.php;
       error_page 403 = /core/templates/403.php;
       error_page 404 = /core/templates/404.php;
       location = /robots.txt {
           allow all;
           log_not_found off;
           access_log off;
       }
       location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
               deny all;
       }
       location / {
               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/ index.php;
       }
       location ~ ^(.+?\.php)(/.*)?$ {
               try_files $1 = 404;
               include fastcgi_params;
               fastcgi_param SCRIPT_FILENAME $document_root$1;
               fastcgi_param PATH_INFO $2;
               #fastcgi_param HTTPS on;
               #fastcgi_pass unix:/run/php-fpm/www.sock;
               fastcgi_pass 127.0.0.1:9000;
       }
       location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
               expires modified +30d;
               access_log off;
       }
}

Проверяем доступ из браузера

http://<NEXTCLOUD_IP>/

Вариант 2. Доступ HTTPS по доменному имени по локальной сети или с внешнего интерфейса пробросом 443 порта

mkdir /etc/nginx/ssl

cd /etc/nginx/ssl

openssl req -new -x509 -days 1461 -nodes -out cert.pem -keyout cert.key -subj "/C=RU/ST=SPb/L=SPb/O=Global Security/OU=IT Department/CN=cloud.domain123.ru/CN=cloud"

nano /etc/nginx/conf.d/default.conf

server {
       listen 80;
       server_name cloud.domain123.ru;
       return 301 https://$server_name$request_uri;
}
server {
       listen 443 ssl;
       server_name cloud.domain123.ru;
       ssl_certificate /etc/nginx/ssl/cert.pem;
       ssl_certificate_key /etc/nginx/ssl/cert.key;
       root /var/www/cloud;
       add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
       client_max_body_size 10G;
       fastcgi_buffers 64 4K;
       rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
       rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
       rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
       index index.php;
       error_page 403 = /core/templates/403.php;
       error_page 404 = /core/templates/404.php;
       location = /robots.txt {
           allow all;
           log_not_found off;
           access_log off;
       }
       location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
               deny all;
       }
       location / {
               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/ index.php;
       }
       location ~ ^(.+?\.php)(/.*)?$ {
               try_files $1 = 404;
               include fastcgi_params;
               fastcgi_param SCRIPT_FILENAME $document_root$1;
               fastcgi_param PATH_INFO $2;
               fastcgi_param HTTPS on;
               #fastcgi_pass unix:/run/php-fpm/www.sock;
               fastcgi_pass 127.0.0.1:9000;
       }
       location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
               expires modified +30d;
               access_log off;
       }
}

systemctl enable php-fpm

systemctl restart php-fpm

systemctl enable nginx

systemctl restart nginx

Проверяем доступ из браузера

https://<NEXTCLOUD_DOMAIN>/

Дополнительно

Дополнительные домены или адреса, по которым доступен nextcloud:

trusted_domains в файле nano /var/www/cloud/config/config.php