当前位置:   article > 正文

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

centos9安装nextcloud

目录

 一键安装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已经关闭

  1. #!/bin/bash
  2. # 确保脚本以root权限运行
  3. if [ "$EUID" -ne 0 ]; then
  4. echo "请以root用户运行此脚本"
  5. exit
  6. fi
  7. # 检查并卸载旧版本的PHP
  8. echo "检查并卸载旧版本的PHP..."
  9. if php -v > /dev/null 2>&1; then
  10. yum remove -y php*
  11. fi
  12. # 安装EPEL仓库和Remi仓库
  13. echo "安装EPEL仓库和Remi仓库..."
  14. yum install -y epel-release
  15. yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
  16. # 安装yum-utils,如果尚未安装
  17. echo "检查并安装yum-utils..."
  18. if ! command -v yum-config-manager &> /dev/null; then
  19. yum install -y yum-utils
  20. fi
  21. # 启用PHP 8.0仓库并安装PHP及其扩展
  22. echo "启用PHP 8.0仓库并安装PHP..."
  23. yum-config-manager --enable remi-php80
  24. 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
  25. # 启动PHP-FPM服务并设置开机自启
  26. echo "启动PHP-FPM服务并设置开机自启..."
  27. systemctl start php-fpm
  28. systemctl enable php-fpm
  29. # 安装Apache服务器
  30. echo "安装Apache服务器..."
  31. yum remove httpd*
  32. yum install httpd
  33. systemctl start httpd
  34. systemctl enable httpd
  35. # 开放CentOS 7的80端口并配置防火墙
  36. echo "开放80端口并配置防火墙..."
  37. systemctl stop firewalld
  38. firewall-cmd --zone=public --add-port=80/tcp --permanent
  39. firewall-cmd --reload
  40. # 获取Nextcloud安装包并解压
  41. echo "获取Nextcloud安装包并解压..."
  42. wget https://download.nextcloud.com/server/release/latest.zip
  43. yum install -y unzip
  44. unzip latest.zip -d /var/www/html
  45. # 将Nextcloud文件转移到Apache根目录并设置权限
  46. echo "设置Nextcloud文件权限..."
  47. chown -R apache:apache /var/www/html
  48. chmod -R 755 /var/www/html
  49. # 关闭SELinux
  50. echo "关闭SELinux..."
  51. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  52. setenforce 0
  53. echo "Nextcloud安装准备完成,现在可以进行前端配置。"
  54. # 注意:以上脚本不包含数据库安装和配置步骤,需要用户自行配置数据库。

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

无法正常复制分享链接

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

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

  1. # 关闭httpd的代理 关闭自启动
  2. systemctl stop httpd
  3. systemctl disable httpd
  4. # 安装nginx
  5. yum -y install nginx

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

  1. sudo mkdir -p /etc/nginx/certs
  2. 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的配置文件。在 /etc/nginx/conf.d/​ 或者 /etc/nginx/sites-available/​ 目录下创建一个新的配置文件,例如 nextcloud.conf​

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

内容如下(实例)

  1. upstream php-handler {
  2. server 127.0.0.1:9000;
  3. #server unix:/var/run/php/php7.4-fpm.sock;
  4. }
  5. # Set the `immutable` cache control options only for assets with a cache busting `v` argument
  6. map $arg_v $asset_immutable {
  7. "" "";
  8. default "immutable";
  9. }
  10. server {
  11. listen 80;
  12. listen [::]:80;
  13. server_name 192.168.252.74;
  14. # Prevent nginx HTTP Server Detection
  15. server_tokens off;
  16. # Enforce HTTPS
  17. return 301 https://$server_name$request_uri;
  18. }
  19. server {
  20. listen 443 ssl http2;
  21. listen [::]:443 ssl http2;
  22. server_name 192.168.252.74;
  23. # Path to the root of your installation
  24. root /var/www/html;
  25. # Use Mozilla's guidelines for SSL/TLS settings
  26. # https://mozilla.github.io/server-side-tls/ssl-config-generator/
  27. ssl_certificate /etc/nginx/certs/nextcloud.crt; # 与上面的相同
  28. ssl_certificate_key /etc/nginx/certs/nextcloud.key; # 与上面的相同
  29. # Prevent nginx HTTP Server Detection
  30. server_tokens off;
  31. # HSTS settings
  32. # WARNING: Only add the preload option once you read about
  33. # the consequences in https://hstspreload.org/. This option
  34. # will add the domain to a hardcoded list that is shipped
  35. # in all major browsers and getting removed from this list
  36. # could take several months.
  37. #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
  38. # set max upload size and increase upload timeout:
  39. client_max_body_size 8192M;
  40. client_body_timeout 300s;
  41. fastcgi_buffers 64 4K;
  42. # Enable gzip but do not remove ETag headers
  43. gzip on;
  44. gzip_vary on;
  45. gzip_comp_level 4;
  46. gzip_min_length 256;
  47. gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  48. 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;
  49. # Pagespeed is not supported by Nextcloud, so if your server is built
  50. # with the `ngx_pagespeed` module, uncomment this line to disable it.
  51. #pagespeed off;
  52. # The settings allows you to optimize the HTTP2 bandwitdth.
  53. # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
  54. # for tunning hints
  55. client_body_buffer_size 512k;
  56. # HTTP response headers borrowed from Nextcloud `.htaccess`
  57. add_header Referrer-Policy "no-referrer" always;
  58. add_header X-Content-Type-Options "nosniff" always;
  59. add_header X-Download-Options "noopen" always;
  60. add_header X-Frame-Options "SAMEORIGIN" always;
  61. add_header X-Permitted-Cross-Domain-Policies "none" always;
  62. add_header X-Robots-Tag "none" always;
  63. add_header X-XSS-Protection "1; mode=block" always;
  64. # Remove X-Powered-By, which is an information leak
  65. fastcgi_hide_header X-Powered-By;
  66. # Specify how to handle directories -- specifying `/index.php$request_uri`
  67. # here as the fallback means that Nginx always exhibits the desired behaviour
  68. # when a client requests a path that corresponds to a directory that exists
  69. # on the server. In particular, if that directory contains an index.php file,
  70. # that file is correctly served; if it doesn't, then the request is passed to
  71. # the front-end controller. This consistent behaviour means that we don't need
  72. # to specify custom rules for certain paths (e.g. images and other assets,
  73. # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
  74. # `try_files $uri $uri/ /index.php$request_uri`
  75. # always provides the desired behaviour.
  76. index index.php index.html /index.php$request_uri;
  77. # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
  78. location = / {
  79. if ( $http_user_agent ~ ^DavClnt ) {
  80. return 302 /remote.php/webdav/$is_args$args;
  81. }
  82. }
  83. location = /robots.txt {
  84. allow all;
  85. log_not_found off;
  86. access_log off;
  87. }
  88. # Make a regex exception for `/.well-known` so that clients can still
  89. # access it despite the existence of the regex rule
  90. # `location ~ /(\.|autotest|...)` which would otherwise handle requests
  91. # for `/.well-known`.
  92. location ^~ /.well-known {
  93. # The rules in this block are an adaptation of the rules
  94. # in `.htaccess` that concern `/.well-known`.
  95. location = /.well-known/carddav { return 301 /remote.php/dav/; }
  96. location = /.well-known/caldav { return 301 /remote.php/dav/; }
  97. location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
  98. location /.well-known/pki-validation { try_files $uri $uri/ =404; }
  99. # Let Nextcloud's API for `/.well-known` URIs handle all other
  100. # requests by passing them to the front-end controller.
  101. return 301 /index.php$request_uri;
  102. }
  103. # Rules borrowed from `.htaccess` to hide certain paths from clients
  104. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
  105. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
  106. # Ensure this block, which passes PHP files to the PHP process, is above the blocks
  107. # which handle static assets (as seen below). If this block is not declared first,
  108. # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
  109. # to the URI, resulting in a HTTP 500 error response.
  110. location ~ \.php(?:$|/) {
  111. # Required for legacy support
  112. rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
  113. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  114. set $path_info $fastcgi_path_info;
  115. try_files $fastcgi_script_name =404;
  116. include fastcgi_params;
  117. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  118. fastcgi_param PATH_INFO $path_info;
  119. fastcgi_param HTTPS on;
  120. fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
  121. fastcgi_param front_controller_active true; # Enable pretty urls
  122. fastcgi_pass php-handler;
  123. fastcgi_intercept_errors on;
  124. fastcgi_request_buffering off;
  125. fastcgi_max_temp_file_size 0;
  126. }
  127. location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
  128. try_files $uri /index.php$request_uri;
  129. add_header Cache-Control "public, max-age=15778463, $asset_immutable";
  130. access_log off; # Optional: Don't log access to assets
  131. location ~ \.wasm$ {
  132. default_type application/wasm;
  133. }
  134. }
  135. location ~ \.woff2?$ {
  136. try_files $uri /index.php$request_uri;
  137. expires 7d; # Cache-Control policy borrowed from `.htaccess`
  138. access_log off; # Optional: Don't log access to assets
  139. }
  140. # Rule borrowed from `.htaccess`
  141. location /remote {
  142. return 301 /remote.php$request_uri;
  143. }
  144. location / {
  145. try_files $uri $uri/ /index.php$request_uri;
  146. }
  147. }

其中需要更改的配置为

原文中的修改的配置为

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
  1. nginx -t  # 检查配置是否正确
  2. systemctl reload nginx  # 重新加载配置
  3. systemctl start nginx
  4. systemctl enable nginx  # 开机自启
  5. systemctl status nginx.service  # 查看运行状态

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/719196
推荐阅读
相关标签
  

闽ICP备14008679号