Debian12搭建Nextcloud最新版并frp到二级域名

news2024/9/23 11:14:35

起因:因为台风的原因,要居家办公,但正值公司业务最要紧的时刻,所以需要搭建远程共享,结果发现基于原有的经验,已经难以适应版本更新带来的问题,所以就解决方法,进行了一次重新总结,作为记录,也希望能帮到有类似需求的读者。

一、平台环境的搭建

1.1.Mariadb数据库的安装。

采用apt命令直接安装就可以是 10.11.3版。主要是对其进行设置,开启数据库通过远程登录进行管理的功能。

apt update
apt install mariadb-server
#安装结束,进行配置
mysql_secure_installation
root@Home:~# mysql -u root
##以下为mysql环境下的操作
mysql> select User, host from mysql.user ;   #查看一下当前的账户信息
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%'  IDENTIFIED BY '147258369' ; #设定root可远程登录
mysql> select User, host from mysql.user ; 再查看一下当前的账户信息,增加了一个 root   %
mysql> quit ;
 
### 备注: 单独设置 root@localhost 的秘密
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '147258369';

1.2. nginx稳定版的安装

当前nginx最常用的是1.22版,但稳定版已经发布到1.24了。对于系统没有最前沿要求的,可以继续apt直接装就可以了。要安装最新版,还是要按照官方说明进行前置环境的安装,然后才可以。

###以下命令是在debian12最小化安装环境进行,没有sudo命令,直接以root账户操作的!!!
##先安装一些必要的软件。主要是下载工具,key、验证文件、源地址文件的导入工具等
 apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
 
## 下载key文件,并导入
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
 
## 对下载的文件的验证
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
 
## 设置稳定版nginx的安装源的地址
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
 
## 进行声明,告诉debian11系统,按照我们所设定的安装包来进行安装
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n"     | tee /etc/apt/preferences.d/99nginx
 
## 真正的安装
apt update
apt install nginx

1.3 安装php-fpm

apt 默认安装即可。主要是安装必须的插件

apt install php-fpm php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip

1.4 配置nginx和php

#
    location ~ \.php$ {
        root           /usr/share/nginx/nextcloud;
	#fastcgi_pass   127.0.0.1:9000;
	fastcgi_pass unix:/run/php/php-fpm.sock;  ## 这里使用的是sockt连接方式
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/nextcloud$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

编写info.php

cat info.php

<?php
phpinfo();
?>

二、 Nextcloud的下载和解压缩

这个比较简单。看官网介绍即可

在debian12 中, 我安装的nginx的默认路径是 /usr/share/nginx/html   这里根据配置文件的需要,将nextcloud 直接放在了和html同级别的位置,也是就是 usr/share/nginx/nextcloud

三、配置nextcloud 的nginx虚拟机

vim /etc/nginx/conf.d/cloud.conf

##  内容如下  可以从官网关于nginx的设置说明中找到,这里是禁用了ssl,以便后面使用frp


upstream php-handler {
	# server 127.0.0.1:9000;
    server unix:/var/run/php/php-fpm.sock;
}

# Set the `immutable` cache control options only for assets with a cache busting `v` argument
map $arg_v $asset_immutable {
    "" "";
    default "immutable";
}


server {
    listen 34567;  ## 这两段最好修改一下,因为电信运营商会封一些默认的80、8080、21等常用端口
    listen [::]:34567;
    server_name cloud.abcd.com;

    # Prevent nginx HTTP Server Detection
    server_tokens off;

    # Enforce HTTPS
    #  return 301 https://$server_name$request_uri;
    # }

    #    server {
    #    listen 443      ssl http2;
    #    listen [::]:443 ssl http2;
    #    server_name cloud.abcd.com;

    # Path to the root of your installation
    root /usr/share/nginx/nextcloud;

    # Use Mozilla's guidelines for SSL/TLS settings
    # https://mozilla.github.io/server-side-tls/ssl-config-generator/
    #    ssl_certificate     /etc/ssl/certs/nginx-selfsigned.crt;
    #    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

    # Prevent nginx HTTP Server Detection
    #    server_tokens off;

    # 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 and increase upload timeout:
    client_max_body_size 512M;
    client_body_timeout 300s;
    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 text/javascript application/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;

    # 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;

    # The settings allows you to optimize the HTTP2 bandwitdth.
    # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
    # for tunning hints
    client_body_buffer_size 512k;

    # 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                      "noindex, nofollow" 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;

    # Add .mjs as a file extension for javascript
    # Either include it in the default mime.types list
    # or include you can include that list explicitly and add the file extension
    # only for Nextcloud like below:
    include mime.types;
    types {
	    #        text/javascript js mjs;
    }

    # 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;

    # 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 rules in this block are an adaptation of the rules
        # in `.htaccess` that concern `/.well-known`.

        location = /.well-known/carddav { return 301 /remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /remote.php/dav/; }

        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

        # Let Nextcloud's API for `/.well-known` URIs handle all other
        # requests by passing them to the front-end controller.
        return 301 /index.php$request_uri;
    }

    # 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(?:$|/) {
        # Required for legacy support
        rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /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 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;

        fastcgi_max_temp_file_size 0;
    }

    # Serve static files
    location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }
    }

    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
    }

    # Rule borrowed from `.htaccess`
    location /remote {
        return 301 /remote.php$request_uri;
    }

    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
}

四、下载phpMyadmin,配置数据库

五、输入nextcloud所在的主机ip,进行安装

六、特殊的配置

全新安装的nextcloud时,会出现过一会,安装页面出现错误;静等到一切安装完成,输入地址,却出现404错误的问题;还有在进入登录页面后,在确定密码没有错误的情况下,无法通过web页面登录;登录次数过多后,因防暴力试错破解机制,导致延迟登录。本文将解决这几个问题

0. 修改配置文件,加入可登录系统的ip

 图中有 0~3 共4个ip,注意没有证书的化,手动输入开头 http:// XXXX-ip/ 来确保非加密网页

1. /var/lib/php/session​ 这个文件夹及其中的文件,权限要和 nginx 、php保持一致。

  目前新安装的nginx,默认使用的账户是   www-data

chown -R www-data:www-data /var/lib/php/session​/

 2. http强制转换为https的问题

不知道从哪个版本开始,安装指导和配置文件内,都开始指向 https了,即便没有申请证书,也会指向和强制把http => https  。 修改配置文件,取消这一设定,保持 http就可以了

vim nextcloud/config/config.php


 3. 如果以为自己记错了密码,反复登录,会出现IP受限的问题

 也可以通过修改配置,取消试错保护的功能。 可以登录,问题解决后,再改回来

方法: 如第2步,在配置文件中添加一行:

 'auth.bruteforce.protection.enabled' => false,

七、frp和转发服务器nginx的配置

这一部分可以参考 Nextcloud 结合frp搭建私有网盘_frp nextcloud_lggirls的博客-CSDN博客

 需要注意的是,在之前的这篇中,还没有强制使用https,比较好转发,但现在不行了。

还有关于转发代理的问题,可以参考: 使用frp结合nginx实现对https的反向代理支持_frp+nginx_lggirls的博客-CSDN博客

在本例子中,我们搭建的nextcloud使用的是http协议,在frp和nginx代理后,也是http协议

代理服务器上的配置:

这里的34567 端口,是frps服务器中的virtual_host 的端口 

server {
        listen      80 default_server;  
        listen      [::]:80 default_server;
        server_name cloud.abcd.com;
 
        location / {
            proxy_pass http://127.0.0.1:34567; 
        }
    }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/958900.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ssm+vue乐购游戏商城系统源码和论文

ssmvue乐购游戏商城系统源码和论文115 开发工具&#xff1a;idea 数据库mysql5.7 数据库链接工具&#xff1a;navcat,小海豚等 技术&#xff1a;ssm 摘 要 随着社会的发展&#xff0c;游戏品种越来越多&#xff0c;计算机的优势和普及使得乐购游戏商城系统的开发成为必需…

气候变化下的DNDC模拟

DNDC&#xff08;Denitrification-Decomposition&#xff0c;反硝化-分解模型&#xff09;是目前国际上最为成功的模拟生物地球化学循环的模型之一&#xff0c;自开发以来&#xff0c;经过不断完善和改进&#xff0c;从模拟简单的农田生态系统发展成为可以模拟几乎所有陆地生态…

[C++网络协议] I/O复用

具有代表性的并发服务器端实现模型和方法&#xff1a; 多进程服务器&#xff1a;通过创建多个进程提供服务。 多路复用服务器&#xff1a;通过捆绑并统一管理I/O对象提供服务。✔ 多线程服务器&#xff1a;通过生成与客户端等量的线程提供服务。 目录 1. I/O复用 2. select函…

数据恢复工具推荐,记好这3款!

“我真的总会因为数据丢失而烦恼。有些文件都不知道什么时候删除的&#xff0c;想找的时候就找不到了。各位朋友有什么好的数据恢复工具可以推荐吗&#xff1f;真的很需要&#xff01;” 无论保存在电脑、u盘、还是手机里的数据&#xff0c;都有可能会被误删或由于各种原因而丢…

Vue框架--Vue中的数据绑定

Vue中有两种数据绑定的方式 1.单向数据绑定(v-band):数据只能够从data流向页面 2.双向数据绑定(v-model):数据不仅仅能够从data流向页面&#xff0c;也可以从页面流向data。 备注: 1.双向绑定一般都应用在表单类元素上。(如:input、select等有value属性值的标签上) 2.…

【开发】视频云存储/安防监控视频智能分析网关V3:明烟/明火检测详解

智能分析网关系列是基于边缘AI计算技术&#xff0c;可对前端摄像头采集的视频流进行实时检测分析&#xff0c;能对监控画面中的人、车、物进行识别。我们的AI边缘计算网关硬件——智能分析网关目前有5个版本&#xff1a;V1、V2、V3、V4、V5&#xff0c;每个版本都能实现对监控视…

iOS开发Swift-6-深色模式,类与对象,MVC模式,弹出框,闭包-趣味问答App

1.创建趣味问答App项目 2.创建一个问题文本&#xff0c;水平居中约束。 创建蓝、红两个按钮&#xff0c;放入Stack View中&#xff0c;给StackView水平居中约束&#xff0c;下边约束&#xff0c;设置两按钮间距为20. 设置进度条view与safe View关系为equal width。设置他们的比…

关于在香橙派安装mysql时遇到的坑

前言 基础环境&#xff1a;硬件&#xff1a;香橙派5操作系统&#xff1a;openkylincpu架构&#xff1a;arm 过程&#xff1a;最近有个任务&#xff0c;要在新的环境中验证一些服务是否可用。目的时向全国产化靠拢。 需要在香橙派上安装openkylin&#xff0c;一开始尝试的是香橙…

A. Channel

题目&#xff1a;样例&#xff1a; 输入 4 5 5 3 -- 5 2 3 - 5 4 2 - 5 0 7 -输出 YES NO MAYBE YES 题意&#xff1a; 给出 目的人数n看到通告的数量&#xff0c;初始人数m上线的数量&#xff0c;通知系统上线q条消息&#xff0c;‘-’表示有人下线&#xff0c;‘’表示有人上…

京东API接口解析,实现按关键字搜索商品

京东开放平台提供了丰富的API接口&#xff0c;用于查询商品、用户、订单等信息。以下是一个基本的示例&#xff0c;解析并实现按关键字搜索商品的API接口。 需要访问京东开放平台并注册一个开发者账号。注册完成后&#xff0c;你需要创建一个应用并获取到API的权限。 在获取到…

不看过程看结果 Web3最霸道架构Intent- Centric能解决啥?

开源区块链网络以太坊诞生的8年里&#xff0c;涌现出不计其数的竞争链&#xff0c;同时也为金融、游戏等场景的链上应用发展奠定了底层基础。唯一令人遗憾的是&#xff0c;8年了&#xff0c;绝大多数互联网用户还是摸不到以区块链为底层的Web3大门。 有数据显示&#xff0c;总…

亚马逊测评的风控挑战与解决方案

做跨境电商测评自养号测评的都知道&#xff0c;亚马逊平台是所有跨境平台中风控最严的&#xff0c;做亚马逊测评实操遇到过各种问题&#xff0c;比如&#xff1a;取消订单&#xff08;砍单&#xff09;、掉评、账号批量被封等等 其实这些问题除了亚马逊自身的风控&#xff0c;…

真香:Alibaba开源GitHub星标100K微服务架构全彩进阶手册

前言&#xff1a; 微服务架构作为一种高效灵活的应用架构&#xff0c;正在成为企业级应用开发的主流选择。在众多的微服务架构指南中&#xff0c;阿里巴巴开源的GitHub微服务架构全彩进阶手册备受瞩目&#xff0c;其100star更是证明了其在开发者社区中的重要地位。 这本手册汇…

微服务演变及怎么拆分微服务

微服务演变 ⼀、微服务演变过程 版本1.0 ⼏年前&#xff0c;⼩明和⼩⽪⼀起创业做⽹上超市。⼩明负责程序开发&#xff0c;⼩⽪负责其他事宜。当时互联⽹还不发 达&#xff0c;⽹上超市还是蓝海。只要功能实现了就能随便赚钱。所以他们的需求很简单&#xff0c;只需要⼀个⽹站…

一文5000字从0到1使用Jmeter实现轻量级的接口自动化测试(图文并茂)

接口测试虽然作为版本的一环&#xff0c;但是也是有一套完整的体系&#xff0c;有接口的功能测试、性能测试、安全测试&#xff1b;同时&#xff0c;由于接口的特性&#xff0c;接口的自动化低成本高收益的&#xff0c;使用一些开源工具或一些轻量级的方法&#xff0c;在测试用…

文心一言 VS 讯飞星火 VS chatgpt (84)-- 算法导论8.2 1题

一、用go语言&#xff0c;参照图8-2 的方法&#xff0c;说明 COUNTING-SORT 在数组 A(6&#xff0c;0&#xff0c;2&#xff0c;0&#xff0c;1&#xff0c;3&#xff0c;4&#xff0c;6&#xff0c;1&#xff0c;3&#xff0c;2)上的操作过程。 文心一言&#xff1a; Counti…

2023-8-31 有边数限制的最短路(bellman-ford)

题目链接&#xff1a;有边数限制的最短路 #include <iostream> #include <cstring> #include <algorithm>using namespace std;const int N 510, M 10010;int n, m, k; int dist[N], backup[N];// 存放边的信息 struct Edge {int a, b, w; }edges[M];void …

mysql group by 字段 与 select 字段

表数据如下&#xff1a; 执行SQL语句1&#xff1a; SELECT * FROM z_course GROUP BY NAME,SEX 结果&#xff1a; 执行SQL语句2&#xff1a; SELECT * FROM z_course GROUP BY NAME sql 1 根据 name&#xff0c;sex 两个字段分组&#xff0c;查询 所有字段&#xff0c;返回结…

GitHub打不开解决方法——授人以渔

打不开GitHub的原因之一&#xff0c;DNS地址解析到了无法访问的ip。&#xff08;为什么无法访问&#xff1f;&#xff09; 1、打开GitHub看是哪个域名无法访问&#xff0c;F12一下 2、DNS解析看对应的域名目前哪个IP可以访问 DNS解析的网址&#xff1a; &#xff08;1&#x…

OpenBSD新版将增加KARL功能:重启换内核

在 OpenBSD 的测试快照中加入了一个新的功能&#xff0c;每次当 OpenBSD 用户重启或升级计算机时都会创建一个独特的内核。该功能被称之为 KARL&#xff08;内核地址随机化链接Kernel Address Randomized Link&#xff09;&#xff0c;即以随机的顺序重新链接其内部的内核文件&…