NextCloud
废话不多说,先上图!冲!

1、LNMP环境搭建nextcloud网盘
环境
| 版本 | |
|---|---|
| Linux | Centos7.8 |
| Nginx | 1.16 |
| Postgresql | 11 |
| PHP | 7.4 |
1.安装NGINX-1.16
yum install nginx -y
yum install yum-utils
systemctl start nginx
systemctl enable nginx
1.1nginx.conf文件
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
#listen 80 default_server;
#listen [::]:80 default_server;
#server_name _;
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
1.2添加nextcloud官方的nginx配置
nextcloud.conf文件
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php/php7.4-fpm.sock;
}
#server {
# listen 80;
# listen [::]:80;
# server_name 182.92.63.240;
# Enforce HTTPS
#return 301 https://$server_name$request_uri;
#}
server {
#listen 443 ssl http2;
#listen [::]:443 ssl http2;
#server_name cloud.example.com;
listen 8080;
server_name 182.92.63.240;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
#ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
#ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
# HSTS settings
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
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;
# Pagespeed is not supported by Nextcloud, so if your server is built
# with the `ngx_pagespeed` module, uncomment this line to disable it.
#pagespeed off;
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /opt/www/nextcloud;
# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour
# when a client requests a path that corresponds to a directory that exists
# on the server. In particular, if that directory contains an index.php file,
# that file is correctly served; if it doesn't, then the request is passed to
# the front-end controller. This consistent behaviour means that we don't need
# to specify custom rules for certain paths (e.g. images and other assets,
# `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
# `try_files $uri $uri/ /index.php$request_uri`
# always provides the desired behaviour.
index index.php index.html /index.php$request_uri;
# Default Cache-Control policy
expires 1m;
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
# The following 6 rules are borrowed from `.htaccess`
rewrite ^/\.well-known/host-meta\.json /public.php?service=host-meta-json last;
rewrite ^/\.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/\.well-known/webfinger /public.php?service=webfinger last;
rewrite ^/\.well-known/nodeinfo /public.php?service=nodeinfo last;
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
try_files $uri $uri/ =404;
}
# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
# which handle static assets (as seen below). If this block is not declared first,
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
# to the URI, resulting in a HTTP 500 error response.
location ~ \.php(?:$|/) {
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 on;
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;
}
location ~ \.(?:css|js|svg|gif)$ {
try_files $uri /index.php$request_uri;
expires 6M; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}
★☆安装最新版nginx如下:
cat >> /etc/yum.repos.d/nginx.repo << EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
#默认情况下,使用稳定的nginx软件包的存储库。如果要使用主线nginx软件包,请运行以下命令:
yum-config-manager --enable nginx-mainline
yum install nginx -y
2.安装postgresql数据库
使用docker部署postgresql
2.1编辑docker-compose.yml
---
version: '3.5'
services:
postgresql:
restart: unless-stopped
container_name: postgresql
image: docker.io/postgres:11
network_mode: host
privileged: true
#command: postgres -c max_connections=256 -c shared_buffers=1024MB -c work_mem=10MB -c effective_cache_size=1024MB -c maintenance_work_mem=128MB -c checkpoint_completion_target=0.9 -c commit_delay=10 -c commit_siblings=4
volumes:
- "/opt/db/postgresql/data/:/var/lib/postgresql/data"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: tyDAL8q9laID
ports:
- 5432:5432
2.2启动postgresql数据库
docker-compose up -d
2.3创建postgresql的用户和权限
CREATE ROLE "nextcloud" login PASSWORD 'dgj66666' CREATEDB;
GRANT CREATE, TEMP, CONNECT ON DATABASE "nextcloud" TO "nextcloud" WITH GRANT OPTION;
如果使用mysql=
2.安装mysql5.7数据库
#下载mysql的rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
#安装
yum localinstall mysql57-community-release-el7-11.noarch.rpm -y
#安装mysql服务
yum install mysql-community-server -y
#启动mysql
systemctl start mysqld
A. 查看默认密码
grep 'temporary password' /var/log/mysqld.log
B. 输入密码进入mysql
mysql -uroot -p
C. 默认大小写字符八位,修改策略
mysql>set global validate_password_policy=0;
D. 更改默认root密码
mysql>alter user 'root'@'localhost' identified by 'dgj66666';
E. 修改生效
mysql>flush privileges;
F. 添加一个允许远程连接的帐户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'dgj66666' WITH GRANT OPTION;
G. 允许root所有远程登录
mysql> use mysql;
mysql> UPDATE user SET Host='%' WHERE User='root';
mysql>flush privileges;
H. 设置默认编码支持utf-8字符
mysql 安装后默认不支持中文,需要修改编码
1、修改/etc/my.conf
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
2、重启mysql服务,查询编码。可以看到已经改过来了
shell> systemctl restart mysqld
shell> mysql -uroot -p
mysql> show variables like 'character%';
3、命令行创建用户,权限
create database nextcloud;
create user nextcloud@localhost identified by 'nextcloud@';
grant all privileges on nextcloud.* to nextcloud@localhost identified by 'nextcloud';
flush privileges;
I. 默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
3.安装启动PHP,php-fpm
#安装第三方源
yum install epel-release -y
#安装工具包( 管理repository及扩展包的工具)
yum -y install yum-utils
#安装PHP 7.4 Remi存储库
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum repolist all |grep php
yum-config-manager --enable remi-php74
#安装配合喷7.4和拓展
yum install -y php \
php-gd \
php-cli \
php-fpm \
php-zip \
php-xml \
php-curl \
php-pear \
php-json \
php-redis \
php-devel \
php-pgsql \
php-mcrypt \
php-bcmath \
php-mysqlnd \
php-mbstring
#yum install -y php php-gd php-cli php-fpm php-zip php-xml php-curl php-pear php-json php-redis php-devel php-pgsql php-mcrypt php-bcmath php-mysqlnd php-mbstring
#启动PHP
systemctl start php-fpm
3.1配置php-fpm
1、vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
2、确保php-fpm运行在指定端口
listen = 127.0.0.1:9000
3、取消注释,启用php-fpm的系统环境变量
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
4、更改三个目录为nginx用户
chown -R nginx:nginx /var/lib/php/session
chown -R nginx:nginx /var/lib/php/wsdlcache
chown -R nginx:nginx /var/lib/php/opcache
5、配置完毕,重启,配置开机自启
systemctl restart php-fpm
systemctl enable php-fpm
4.访问web网页安装
http://ip:8080/
4.1按提示创建管理员用户密码
4.2具体步骤
设置储存 - -> 选择postgresql或者mysql - -> nextcloud的数据库 - -> nextcloud用户 - -> 输入用户密码 - -> 数据库的端口localhost:5432/3306
4.3完成
下一步安装即可完成,至此nextcloud部署完成。
该博客详细介绍了如何在CentOS7.8系统上搭建NextCloud网盘服务,包括使用Nginx 1.16、PostgreSQL 11和PHP 7.4的环境配置,以及Nginx的配置文件设置。同时,提供了安装最新版Nginx的方法,并涉及了PostgreSQL数据库的Docker部署,创建用户和权限的步骤。最后,指导了PHP 7.4的安装与配置,以及启动PHP-FPM服务。整个过程完成后,可以通过Web页面完成NextCloud的安装,包括设置数据库和管理员账号。
811

被折叠的 条评论
为什么被折叠?



