Nextcloud A safe home for all your data.
官方教程 https://docs.nextcloud.com/server/latest/admin_manual/installation/example_ubuntu.html
前置依赖安装 安装MySQL 1 2 3 4 5 6 7 8 9 10 sudo apt install mysql-server ## 初始化一下 sudo mysql_secure_installation ## 查看状态 sudo systemctl status mysql ## 无密码直接登录 sudo mysql -u root -p
如果登录不上,重置一下密码。
密码策略(内网简单密码设置)
1 SET GLOBAL validate_password.policy = LOW;
配置文件vim /etc/mysql/mysql.conf.d/mysqld.cnf 如果需要远程登录:
安装Nginx
配置文件有两个目录:/etc/nginx/sites-available 与 /etc/nginx/sites-enabled
default :为网站配置文件的参考,由于在 nginx 更新时,default 会一同被更新以展示配置文件的变化,所以在配置网站时,不应该直接修改此文件,需要复制为新文件,再进行修改。
sites-enabled : nginx 会加载启动此目录下所有配置。此目录下一般都是软链接,指向 sites-available 目录中的配置文件,可以很方便的启动和关闭网站。
sites-available : 此目录下的配置文件默认不会被 nginx 加载启动,只启动 sites-enabled 目录中有对应软连接的配置。
日志目录 /var/log/nginx
网站目录 /var/www/html
安装PHP 1 2 3 4 sudo apt install php sudo apt install php8.1-fpm libapache2-mod-php8.1 sudo apt install php8.1-curl php8.1-dom php8.1-mbstring php8.1-imagick php8.1-ldap php8.1-imap php8.1-mysql php8.1-gd php8.1-zip php8.1-bz2 php8.1-intl php8.1-smbclient php8.1-bcmath php8.1-gmp php8.1-apcu php8.1-memcached php8.1-redis php8.1-phar sudo apt install libmagickcore-dev
安装NextCloud 1 2 3 mkdir nextcloud cd nextcloud wget https://download.nextcloud.com/server/installer/setup-nextcloud.php
打开http://192.168.31.6/nextcloud/setup-nextcloud.php
报错:Can’t write to the current directory. Please fix this by giving the webserver user write access to the directory.
NextCloud 安装程序无法写入当前目录。web服务通常运行的用户和组不是root,一般是www-data 或 nginx 修改文件用户组
1 2 3 4 sudo chown -R www-data:www-data /var/www/html/nextcloud sudo find /var/www/html/nextcloud -type d -exec chmod 750 {} \; sudo find /var/www/html/nextcloud -type f -exec chmod 640 {} \; sudo systemctl restart nginx
数据库配置 mysql设置用户
1 2 3 CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL PRIVILEGES ON nextcloud.* TO 'localuser'@'localhost'; FLUSH PRIVILEGES;
nginx配置 https://docs.nextcloud.com/server/29/admin_manual/installation/nginx.html
内网HTTP配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 upstream php-handler { server unix:/run/php/php-fpm.sock; } map $arg_v $asset_immutable { "" ""; default ", immutable"; } server { listen 80; listen [::]:80; server_name cloud.example.com; root /var/www/html; server_tokens off; include mime.types; types { application/wasm wasm; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ^~ /.well-known { location = /.well-known/carddav { return 301 /nextcloud/remote.php/dav/; } location = /.well-known/caldav { return 301 /nextcloud/remote.php/dav/; } location /.well-known/acme-challenge { try_files $uri $uri/ =404; } location /.well-known/pki-validation { try_files $uri $uri/ =404; } return 301 /nextcloud/index.php$request_uri; } location ^~ /nextcloud { client_max_body_size 512M; client_body_timeout 300s; 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 text/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm 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; client_body_buffer_size 512k; add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options "nosniff" 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; fastcgi_hide_header X-Powered-By; index index.php index.html /nextcloud/index.php$request_uri; location = /nextcloud { if ( $http_user_agent ~ ^DavClnt ) { return 302 /nextcloud/remote.php/webdav/$is_args$args; } } location ~ ^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; } location ~ ^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; } location ~ \.php(?:$|/) { rewrite ^/nextcloud/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /nextcloud/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 $path_info; fastcgi_param HTTPS off; fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice fastcgi_param front_controller_active true; # Enable pretty urls fastcgi_pass php-handler; 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|ogg|flac)$ { try_files $uri /nextcloud/index.php$request_uri; # HTTP response headers borrowed from Nextcloud `.htaccess` add_header Cache-Control "public, max-age=15778463$asset_immutable"; add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options "nosniff" 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; access_log off; # Optional: Don't log access to assets } location ~ \.woff2?$ { try_files $uri /nextcloud/index.php$request_uri; expires 7d; # Cache-Control policy borrowed from `.htaccess` access_log off; # Optional: Don't log access to assets } location /nextcloud/remote { return 301 /nextcloud/remote.php$request_uri; } location /nextcloud { try_files $uri $uri/ /nextcloud/index.php$request_uri; } } }
语言设置
1 2 3 4 vim nextcloud/config/config.php # 添加 'default_language' => 'zh_CN', 'force_language' => 'zh_CN',
语言对应配置参见https://explore.transifex.com/languages/