NextCloud 搭建教程

一、前言

Nextcloud应该是大家首选的私有网盘了吧,官方教程里面虽然提供了Docker的部署方式,但是属于all in one的自动部署方式,必须要有80和433端口的域名才能进行部署,还不支持“纯本地内网”或者“域名+其他端口

二、安装

2.1、前期准备

Docker、SSH、Nginx等服务的安装

2.2、SSL安装

2.2.1、环境准备

# c编译器
yum -y install gcc gcc-c++ autoconf automake make
# 解析正则的pcre库
yum install -y pcre pcre-devel
# 添加对gzip的支持
yum install -y zlib zlib-devel
# SSL
yum -y install pcre  pcre-devel zlib  zlib-devel openssl openssl-devel
#安装依赖
sudo yum install epel-release

2.3、Nginx安装

test.png

# 解压压缩包
tar -zxvf nginx-1.22.1.tar.gz
#赋予执行权限
chmod +x configure
#开始安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#编译
make
#安装
make install

2.4、SSL证书生成

#证书生成
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /root/aaa/private.key -out /root/aaa/certificate.crt

test.png

2.5、nginx.config配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  你的域名;
		location / {
			 proxy_buffering off;
			 proxy_set_header Host $http_host;                  
			 proxy_set_header Upgrade $http_upgrade;
			 proxy_set_header X-Real-IP $remote_addr;
			 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			 proxy_set_header X-Nginx-Proxy true;                      
			 proxy_set_header X-Forwarded-Proto $scheme;
			 proxy_pass http://127.0.0.1:8088;   
		}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       443 ssl;
        server_name  你的域名;
        #证书文件名称
     	ssl_certificate /root/aaa/ssl/certificate.crt; 
        #私钥文件名称
     	ssl_certificate_key /root/aaa/ssl/private.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        add_header X-Content-Type-Options nosniff;
	    add_header X-XSS-Protection "1; mode=block";
	    add_header X-Robots-Tag none;
	    add_header X-Download-Options noopen;
	    add_header X-Permitted-Cross-Domain-Policies none;
	    add_header Strict-Transport-Security "max-age=15768000";
 
   
	  location = /.well-known/carddav {
		  return 301 $scheme://$host/remote.php/dav;
	  }
	  location = /.well-known/caldav {
		  return 301 $scheme://$host/remote.php/dav;
	  }
	  client_max_body_size 512M;
	  fastcgi_buffers 64 4K;
	  gzip on;
	  gzip_vary on;
	  gzip_comp_level 3;
	  gzip_min_length 1024;
	  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; 
	  location / {
		  # proxy_http_version 1.1;
		  proxy_buffering off;
		  proxy_set_header Host $http_host;
		  proxy_set_header Upgrade $http_upgrade;
		  proxy_set_header X-Real-IP $remote_addr;
		  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		  # proxy_redirect off;
		  proxy_pass http://127.0.0.1:8088;
	  }
    }

}

三、nextcloud安装

3.1、docker安装nextcloud

#拉去镜像
docker pull nextcloud
#创建文件夹
mkdir -p /home/nextcloud
#启动镜像
docker run -d --restart=always -p 8088:80 -v /home/nextcloud:/var/www/html  --name nextcloud nextcloud

3.2、nextcloud配置文件配置config.php

/home/nextcloud/config目录下config.php文件配置

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'upgrade.disable-web' => true,
  'instanceid' => 'ocgq45mamcec',
  'passwordsalt' => 'Xb7Ic4/7wObsMFtSAjWVk/Cgtjwc1l',
  'secret' => 'Y8D29irZTIgDfL0DgxQ653PZt3dDsP3l/idGt/tOKRjnpXsA',
  'trusted_domains' => 
  array (
	  0 => '域名',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '28.0.3.2',
  'overwrite.cli.url' => 'https://域名',
  'dbname' => '数据库',
  'dbhost' => '数据库地址:端口',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '自动生成用户',
  'dbpassword' => '自动生成密码',
  'installed' => true,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'overwriteprotocol' => 'https',
);
'overwriteprotocol' => 'https',指定访问方式是http或者https

四、防火墙配置

4.1、80、443端口放开

#端口添加
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
#白名单端口
firewall-cmd --zone=public --list-ports

#重新加载防火墙端口
firewall-cmd --reload
#停止防火墙
systemctl stop firewalld.service
#启动防火墙
systemctl start firewalld.service

五、系统验证

test.png

注意:MYSQL数据库自行搭建

posted on 2026-08-10 15:33  爱河  阅读(2)  评论(0)    收藏  举报

导航