Centos7.9 脚本一键部署nextcloud,配置Nginx代理Https。

news2024/10/5 21:21:17

目录

 一键安装nextcloud

出现错误TypeError Cannot read properties of undefined (reading ‘writeText‘)

生成自签名SSL证书

编辑Nginx配置文件

启动Nginx


 一键安装nextcloud

本脚本参考文章,本文较长建议先看完在操作!!!

全网最详细CentOS 7下部署最新版nextcloud教程_centos7 安装nextcloud-CSDN博客


Nginx服务配置篇·第三课:NextCloud部署安装-腾讯云开发者社区-腾讯云

此安装脚本不包含安装数据库,且默认授权/var/www/html    为nextcloud的数据目录

并且使用官方推荐的Apache httpd代理/var/www/html 即代理nextcloud(这种方式非https 在v26+版本中会出现无法自动复制分享链接的问题)

且安装后最好重启下 确认SELinux已经关闭

#!/bin/bash

# 确保脚本以root权限运行
if [ "$EUID" -ne 0 ]; then
  echo "请以root用户运行此脚本"
  exit
fi

# 检查并卸载旧版本的PHP
echo "检查并卸载旧版本的PHP..."
if php -v > /dev/null 2>&1; then
  yum remove -y php*
fi

# 安装EPEL仓库和Remi仓库
echo "安装EPEL仓库和Remi仓库..."
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

# 安装yum-utils,如果尚未安装
echo "检查并安装yum-utils..."
if ! command -v yum-config-manager &> /dev/null; then
  yum install -y yum-utils
fi

# 启用PHP 8.0仓库并安装PHP及其扩展
echo "启用PHP 8.0仓库并安装PHP..."
yum-config-manager --enable remi-php80
yum install -y php php-bcmath php-cli php-common php-devel php-fpm php-gd php-intl php-ldap php-mbstring php-mysqlnd php-odbc php-pdo php-pear php-pecl-xmlrpc php-pecl-zip php-process php-snmp php-soap php-sodium php-xml

# 启动PHP-FPM服务并设置开机自启
echo "启动PHP-FPM服务并设置开机自启..."
systemctl start php-fpm
systemctl enable php-fpm

# 安装Apache服务器
echo "安装Apache服务器..."
yum remove httpd*
yum install httpd
systemctl start httpd
systemctl enable httpd

# 开放CentOS 7的80端口并配置防火墙
echo "开放80端口并配置防火墙..."
systemctl stop firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

# 获取Nextcloud安装包并解压
echo "获取Nextcloud安装包并解压..."
wget https://download.nextcloud.com/server/release/latest.zip
yum install -y unzip
unzip latest.zip -d /var/www/html

# 将Nextcloud文件转移到Apache根目录并设置权限
echo "设置Nextcloud文件权限..."
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html

# 关闭SELinux
echo "关闭SELinux..."
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

echo "Nextcloud安装准备完成,现在可以进行前端配置。"

# 注意:以上脚本不包含数据库安装和配置步骤,需要用户自行配置数据库。

上述安装完成后存在一个新的问题

无法正常复制分享链接

出现错误TypeError Cannot read properties of undefined (reading ‘writeText‘)

原因是没有https 导致的,修复此问题的脚本为(依赖于上述步骤)

# 关闭httpd的代理 关闭自启动
systemctl stop httpd
systemctl disable httpd

# 安装nginx
yum -y install nginx

  • 生成自签名SSL证书

首先,我们需要创建一个自签名证书。在你的主机上运行以下命令:

sudo mkdir -p /etc/nginx/certs
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/nextcloud.key -out /etc/nginx/certs/nextcloud.crt

这个随便填写一下即可。

然后检查这两个文件是否存在

/etc/nginx/certs/nextcloud.crt
/etc/nginx/certs/nextcloud.key

  • 编辑Nginx配置文件

然后,我们需要编辑Nginx的配置文件。在 /etc/nginx/conf.d/​ 或者 /etc/nginx/sites-available/​ 目录下创建一个新的配置文件,例如 nextcloud.conf​

nano /etc/nginx/conf.d/nextcloud.conf

内容如下(实例)

upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php/php7.4-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 80;
    listen [::]:80;
    server_name 192.168.252.74;

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

    # Path to the root of your installation
    root /var/www/html;

    # Use Mozilla's guidelines for SSL/TLS settings
    # https://mozilla.github.io/server-side-tls/ssl-config-generator/
    ssl_certificate /etc/nginx/certs/nextcloud.crt;  # 与上面的相同
    ssl_certificate_key /etc/nginx/certs/nextcloud.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 8192M;
    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 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                         "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;

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

    location ~ \.(?:css|js|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;
    }
}

其中需要更改的配置为

原文中的修改的配置为

server_name cloud.example.com; #更改为自己的域名

root /var/www/nextcloud; #更改为你的nextcloud目录

ssl_certificate /etc/ssl/nginx/cloud.example.com.crt; #SSL证书目录,一般放.pem根证书 ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key; #SSL证书目录,.key私钥

笔者修改的是

  • /var/www/html      你的代理的nextcloud的目录 这里面包含了启动的网页
  • 192.168.252.74    更改为你的IP或者域名,笔者这里是直接使用ip代替域名

  • client_max_body_size 8192M;      此设置为你的web端可以上传的文件大小的上限,笔者设置的是8G

  • ssl_certificate /etc/nginx/certs/nextcloud.crt;  # 你的秘钥文件

    ssl_certificate_key /etc/nginx/certs/nextcloud.key;   # 你的秘钥文件

启动Nginx
nginx -t  # 检查配置是否正确
systemctl reload nginx  # 重新加载配置
systemctl start nginx
systemctl enable nginx  # 开机自启
systemctl status nginx.service  # 查看运行状态

最后使用https访问你的域名/ip   比如https://192.168.252.74/

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

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

相关文章

效率工具:企业微信机器人完成脚本工作-异常监控(sql篇)

效率工具:定时完成脚本工作(sql篇) 背景:elon在公司需要人工查看某些数据是否异常,并发送到指定企业微信群中。 处理步骤: 工具:企业微信中有机器人 可以指定webhook地址嵌入到脚本中&#xf…

C#语法知识之条件分支语句

4、条件分支语句 目录 4、条件分支语句1、条件分支语句 if1、作用2、if语句3、if...else语句4、if...else if...else语句思考1 只需要0~9数字思考2 语句块 2、条件分支语句 switch1、作用2、基本语法3、default可省略4、自定义常量5、贯穿 1、条件分支语句 if 1、作用 //让顺…

Hive进阶(3)----Checkpoint机制(赋图助君理解)

Checkpoint机制 一、Checkpoint机制概念 本机制可以参考《Hadoop权威指南》第十一章: fsimage文件其实是Hadoop文件系统元数据的一个永久性的检查点,其中包含Hadoop文件系统中的所有目录和文件idnode的序列化信息;fsimage包含Hadoop文件系统…

SpringBoot(一)【入门】

前言 1、SpringBoot 快速入门 1.1、SpringBoot 简介 SpringBoot 是用来简化 Spring 应用的初始搭建以及开发过程 首先我们回顾一下 SpringMVC 项目的开发过程: 导入依赖(javax.servlet-api 和 spring-webmvc)Servlet 容器配置类&#xff…

Pytest精通指南(14)Parametrize之indirect(间接参数)

文章目录 官方概念概念分析官方示例示例分析验证indirect为True但不指定fixture验证indirect为True但不存在fixture 官方概念 概念分析 在pytest的pytest.mark.parametrize装饰器中,indirect参数用于指示是否应该从fixtures中解析参数值,而不是直接使用提…

爆炸之linux-nacos2.0系列集群安装部署

一、环境配置 1、新建磁盘分区 fdisk /dev/vdb 2、创建文件系统 mkfs.xfs /dev/vdb13、创建挂载点: 在 / 目录下创建一个新的目录作为挂载点。/afc 目录 mkdir /afc4、挂载磁盘: 使用 mount 命令将磁盘挂载到新创建的目录。 mount /dev/vdb /afc5、…

Yoshua Bengio独家专访:我不想把大模型未来押注在Scaling Law上,AGI路上要“注意安全”...

导读 漫长的30年间,数度从主流方向的超然出走,是Bengio的制胜秘诀。这种不盲从主流的风格体现在他研究生涯的方方面面。 90年代末期,神经网络被打入冷宫,Bengio的论文多次遭拒,连学生们也开始担心,和他一起…

Vue之v-on事件修饰符的含义及使用

背景:Vue 拆封了一个组件,在组件里面会使用一个方法来改变父组件传过来的值, 但是在子组件里面操作父组件的数据变更,实在比较麻烦(因为单向数据流), So 能不能直接在组件上面绑定事件方法呢&…

springSecurity-记住我(Remember me)

一.记住我概述 Remember me(记住我)记住我,当用户发起登录勾选了记住我,在一定的时间内再次登录就不用输入用户名和密码了,即使浏览器退出重新打开也是如此。 二.流程分析 在SpringSecurity中提供RememberMeAuthenticationFilter过滤器来实…

实时动作检测 | 基于Pytorch+YOLOv5+SlowFast实现的视频流实时动作检测算法_支持多目标的跟踪检测

项目应用场景 面向视频流场景的多目标实时动作检测,项目使用 Pytorch YOLOv5 SlowFast 算法实现。 项目效果 项目细节 > 具体参见项目 README.md (1) 创建 Python 开发环境 conda create -n {your_env_name} python3.7.11 conda activate {your_env_name} (2…

npm镜像源的查看和切换

前言 原域名https://registry.npm.taobao.org/ 原来的淘宝镜像已经不行了,当npm去taobao时,会出现一个证书过期的提示. 下面的是最新的地址: 切换到淘宝镜像(最新的地址) #最新地址 淘宝 NPM 镜像站喊你切换新域名啦! npm config set registry https://registry.npmmirror.com…

00_Linux

文章目录 LinuxLinux操作系统的组成Linux的文件系统Linux操作系统中的文件类型Linux操作系统的组织结构 Linux vs WindowsNAT vs 桥接模式 vs 仅主机Linux Shell命令Linux⽂件与⽬录管理相关指令目录文件普通文件文本编辑 用户管理添加用户删除用户用户组管理 文件权限管理权限…

视频教程下载:用ChatGPT快速提升股票投资能力

学完此视频后可以获得: 学习如何使用人工智能/Chatgpt进行基础/快速/高级财务与研究分析 学习如何使用人工智能/Chatgpt对任何公司进行定性投资研究 学习如何使用人工智能/Chatgpt对任何公司进行定量投资研究 学习如何使用人工智能/Chatgpt创建、预测和分析财务…

C语言(二维数组)

Hi~!这里是奋斗的小羊,很荣幸各位能阅读我的文章,诚请评论指点,关注收藏,欢迎欢迎~~ 💥个人主页:小羊在奋斗 💥所属专栏:C语言 本系列文章为个人学习笔记&#x…

Mac下brew安装php7.4

这里作者挂了梯子,所以很流畅! brew的下载,可参考另外一篇博文~Homebrew 安装与卸载 1、将第三方仓库加入brew brew tap shivammathur/php2、安装指定版本的PHP brew install php7.43、替换Mac自带PHP环境并刷新环境变量 -> …

【uniapp】uniapp返回上一页,并实现刷新界面数据

在uniapp中,经常会有返回上一页的情况,官方提供有 uni.navigateBack 这个api来实现效果,但是此方法返回到上一页之后页面并不会自动刷新(不会触发上一页的onLoad()方法)。 使用场景 从一个列表界面点击新增按钮&…

ASP.NET基于Web Mail收发系统设计与开发

摘 要 互联网络技术的不断发展,电子邮件服务已经成为人们基本的信息交互手段,也是网络服务中最早和最基本的服务之一。传统邮件系统大多是基于C/S结构,如Lotus notes、Microsoft Exchange Server等,这些邮件系统占用相对较多的服…

【氮化镓】GaN HEMT失效物理和可靠性

概述: 本文是一篇关于AlGaN/GaN基高电子迁移率晶体管(HEMTs)的失效物理和可靠性研究的综述文章,发表在2013年10月的《IEEE Transactions on Electron Devices》上。文章由Enrico Zanoni等人撰写,主要关注了影响栅极边缘和肖特基结的失效机制,并探讨了提高这些器件可靠性…

未来趋势:探索Facebook在数字化时代的发展方向

在当今日益数字化的时代,社交媒体已经成为人们日常生活中不可或缺的一部分。Facebook,作为全球最大的社交媒体平台,一直处于行业的前沿,不断地探索和引领社交媒体的发展趋势。本文将深入探讨Facebook在数字化时代的发展方向&#…

算法一:数字 - 两数之和

给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。 来源:力扣(LeetCode) 链接&#xf…