GNU/Linux >> Linux の 問題 >  >> Ubuntu

Ubuntu 20.04 LTSにNginxを使用してNextcloudをインストールします-ステップバイステップガイド?

Nextcloudは、オープンソースの自己ホスト型ファイル同期および共有アプリケーション(カレンダー、連絡先、ドキュメント、電子メールなど)です。 Nextcloudの開発者は、ユーザーにより安全なプラットフォーム、バグの減少、全体的に優れた製品を提供するために最善を尽くしています。

ここLinuxAPTでは、サーバー管理サービスの一環として、お客様が関連するオープンソースソフトウェアのインストールクエリを実行するのを定期的に支援しています。

これに関連して、Ubuntu20.04LTSにNextcloudをインストールする方法を検討します。


Ubuntu 20.04 LTSFocalFossaにNextcloudをインストールして構成する手順

1.システムアップデートを実行します

まず、ターミナルで次のaptコマンドを実行して、すべてのシステムパッケージが最新であることを確認します。

$ sudo apt update
$ sudo apt upgrade


2.NginxWebサーバーをインストールします

ここでは、ApacheWebサーバーの代わりにNginxWebサーバーを使用します。 aptコマンドを使用してNginxWebサーバーをインストールします:

$ sudo apt install nginx -y

インストールが完了したら、Nginxサービスを開始し、systemctlを使用してシステムの起動時に毎回サービスを起動できるようにします。

$ systemctl start nginx
$ systemctl enable nginx

Nginxサービスが稼働します。次のコマンドを使用して確認できます:

$ systemctl status nginx


3.PHPのインストールと構成

ここでは、PHP7.4-FPMを使用します。デフォルトでは、Ubuntu20.04にはデフォルトバージョンのPHP7.4が付属しています。

以下のaptコマンドを使用して、Nextcloudに必要なPHPおよびPHP-FPMパッケージをインストールします。

$ sudo apt install php-fpm php-curl php-cli php-mysql php-gd php-common php-xml php-json php-intl php-pear php-imagick php-dev php-common php-mbstring php-zip php-soap php-bz2 -y

インストールが完了したら、php-fpmとphp-cliのphp.iniファイルを構成します。

'/etc/php/7.4'ディレクトリに移動します:

$ cd /etc/php/7.4/

vimを使用してphp-fpmおよびphp-cliのphp.iniファイルを編集します:

vim fpm/php.ini
vim cli/php.ini

'date.timezone'行のコメントを解除し、独自のタイムゾーンで値を変更します:

date.timezone=オーストラリア/シドニー

'cgi.fix_pathinfo'行のコメントを解除し、値を'0'に変更します。

cgi.fix_pathinfo=0

保存して終了します。

次に、php-fpmプール構成「www.conf」を編集します。

$ vim fpm/pool.d/www.conf

以下の行のコメントを解除します:

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

保存して終了します。

PHP7.4-FPMサービスを再起動し、システムの起動時に毎回起動できるようにします。

$ systemctl restart php7.4-fpm
$ systemctl enable php7.4-fpm

次に、次のコマンドを使用してPHP-FPMサービスを確認します。

$ ss -xa | grep php
$ systemctl status php7.4-fpm

そして、php-fpmがsockファイル'/run/php/php7.4-fpm.sock'の下で稼働していることがわかります。


4.MariaDBサーバーのインストールと構成

ここでは、最新のMariaDBバージョンをインストールし、nextcloudインストール用の新しいデータベースを作成します。最新バージョンのMariaDBパッケージは、デフォルトでリポジトリで利用できます。

以下のaptコマンドを使用してMariaDBサーバーの最新バージョンをインストールします。

$ sudo apt install mariadb-server -y

インストールが完了したら、MariaDBサービスを開始し、システムの起動時に毎回起動できるようにします。

$ systemctl start mariadb
$ systemctl enable mariadb

次に、次のコマンドを使用してMySQLサービスを確認します。$

$ systemctl status mariadb

MariaDBサーバーがシステム上で稼働していることがわかります。

次に、「mysql_secure_installation」コマンドを使用してMariaDBルートパスワードを構成します。

次のコマンドを実行します:

$ mysql_secure_installation

そして、MariaDBサーバーの構成を求められます。また、MariaDBサーバーの新しいルートパスワードを入力します:

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

そして、MariaDBルートパスワードが設定されました。

次に、nextcloudインストール用の新しいデータベースを作成します。ユーザー「nextclouduser」とパスワード「Nextclouduser421@」で「nextcloud_db」という名前の新しいデータベースを作成します。

mysqlコマンドを使用してrootユーザーとしてMySQLシェルにログインします:

$ mysql -u root -p

MYSQLルートパスワードを入力してください

次に、次のMySQLクエリを実行して、パスワードを使用してデータベースとユーザーを作成します。

create database nextcloud_db;
create user nextclouduser@localhost identified by 'Nextclouduser421@';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'Nextclouduser421@';
flush privileges;


5.SSLを生成するLet'sEncrypt

ここでは、Letsencryptの無料SSLを使用してnextcloudを保護し、letsencryptツールを使用して証明書ファイルを生成します。

ドメイン名がない場合、またはローカルコンピューターにnextcloudをインストールしていない場合は、OpenSSLを使用して自己署名証明書を生成できます。

以下のaptコマンドを使用して「letsencrypt」ツールをインストールします。

$ sudo apt install certbot -y

インストールが完了したら、nginxサービスを停止します:

$ systemctl stop nginx

次に、cerbotコマンドラインコマンドを使用して、ドメイン名「nextcloud.linuxapt.com」のSSL証明書を生成します。

$ certbot certonly --standalone -d nextcloud.linuxapt.com

メールアドレスの入力を求められ、更新通知に使用されます。 Letsencrypt TOS契約の場合は「A」と入力して同意し、共有メールアドレスの場合は「N」と入力して「いいえ」と入力します。

これで、netxcloudドメイン名のSSL証明書Letsencryptは、「/ etc /letsencrypt / live/your-domain」ディレクトリにあるすべてのSSLファイル/証明書を使用して生成されます。


6.Nextcloudをダウンロード

nextcloudソースコードをダウンロードする前に、unzipパッケージがシステムにインストールされていることを確認してください。パッケージがない場合は、以下のaptコマンドを使用してインストールしてください。

$ sudo apt install wget unzip zip -y

次に、「/ var / www」ディレクトリに移動し、次のコマンドを使用してNextcloudの最新バージョンをダウンロードします。

$ cd /var/www/
$ wget -q https://download.nextcloud.com/server/releases/latest.zip

Nextcloudソースコードを抽出すると、新しいディレクトリ「netxcloud」が取得され、nextcloudディレクトリの所有権がユーザー「www-data」に変更されます:

$ unzip -qq latest.zip
$ sudo chown -R www-data:www-data /var/www/nextcloud

これで、Nextcloudは「/ var / www / nextcloud」ディレクトリの下にダウンロードされ、Webルートディレクトリになります。


7.Nextcloud用にNginx仮想ホストを構成する

このステップでは、nextcloud用にnginx仮想ホストを構成します。 HTTPS接続で実行するようにnextcloudを構成し、HTTP接続を安全なHTTPS接続に自動的に強制します。

次に、「/ etc / nginx / sites-available」ディレクトリに移動し、新しい仮想ホストファイル「nextcloud」を作成します:

$ cd /etc/nginx/sites-available/
$ vim nextcloud

このファイルに、次のnextcloud仮想ホスト構成を貼り付けます:

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 nextcloud.linuxapt.com;
    # enforce https
    return 301 https://$server_name:443$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name nextcloud.linuxapt.com;
    # Use Mozilla's guidelines for SSL/TLS settings
    # https://mozilla.github.io/server-side-tls/ssl-config-generator/
    # NOTE: some settings below might be redundant
    ssl_certificate /etc/letsencrypt/live/nextcloud.linuxapt.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/nextcloud.linuxapt.com/privkey.pem;
    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
    #
    # 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 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 /var/www/nextcloud;
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
    # The following rule is only needed for the Social app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
    location = /.well-known/carddav {
      return 301 $scheme://$host:$server_port/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host:$server_port/remote.php/dav;
    }
    # 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;
    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;
    location / {
        rewrite ^ /index.php;
    }
    location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
        deny all;
    }
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }
    location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.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;
        # Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        # Enable pretty urls
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }
    location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
        try_files $uri/ =404;
        index index.php;
    }
    # Adding the cache control header for js, css and map files
    # Make sure it is BELOW the PHP block
    location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463";
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
        #
        # 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 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;
        # Optional: Don't log access to assets
        access_log off;
    }
    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
        try_files $uri /index.php$request_uri;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

保存して終了します。

仮想ホストを有効にして構成をテストし、エラーがないことを確認します。

$ ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
$ nginx -t

次に、以下のsystemctlコマンドを使用してPHP7.4-FPMサービスとnginxサービスを再起動します。

$ systemctl restart nginx
$ systemctl restart php7.4-fpm


8.UFWファイアウォールを構成する

ここでは、ファイアウォールをオンにし、UbuntuにUFWファイアウォールを使用します。

以下のコマンドを使用して、SSH、HTTP、HTTPSをUFWファイアウォールリストに追加します。

for svc in ssh http https
do
ufw allow $svc
done

その後、UFWファイアウォールを有効にして、許可されているサービスとポートを確認します。

$ ufw enable
$ ufw status numbered

そして、HTTPポート80を取得し、HTTPSポート443がリストに含まれます。


Nextcloud Webインターフェイスにアクセスする方法は?

NextcloudはデフォルトでHTTPポート80で利用可能になります。

お気に入りのブラウザを開き、https://your-domain.com/またはhttps://server-ip-address/に移動して、インストールを完了するために必要な手順を完了します。

Nextcloudで何をするかはあなた次第です。

新しいモジュールを追加することも、クラウドベースのファイル同期および共有として使用することもできます。

Androidアプリをインストールし、ownCloudデスクトップクライアントを利用することもできます(Nextcloudで正常に動作します)。



Ubuntu
  1. Ubuntu 20.04 LTSにPrestaShopをインストールします-ステップバイステップガイド?

  2. Ubuntu 20.04 LTSにXAMPPをインストールします-ステップバイステップガイド?

  3. Ubuntu 20.04 LTSにMailSpringをインストールします-ステップバイステップガイド?

  1. Ubuntu 20.04 LTSにHPLIPをインストールします-ステップバイステップガイド?

  2. Ubuntu 20.04 LTSにInfluxDBをインストールします-ステップバイステップガイド?

  3. Ubuntu 20.04 LTSにAngularをインストールする-ステップバイステップガイド?

  1. Ubuntu 20.04 LTSにOwnCloudをインストールします-ステップバイステップガイド?

  2. Ubuntu 20.04 LTSにAdminerをインストールします-ステップバイステップガイド?

  3. Ubuntu 20.04 LTSにPowerShellをインストールする-ステップバイステップガイド?