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

Nginxを使用してDrupalをインストールし、Ubuntu20.04LTSでSSLを暗号化する方法

Drupalは、無料のオープンソースコンテンツ管理システムであり、Webおよび携帯電話用のデジタルコンテンツの作成と配信を支援します。これはPHPで記述されており、世界中の多くの組織で使用されています。 Drupalを使用すると、小さなブログから大規模な企業Webサイトまで、さまざまなタイプのWebサイトを作成できます。使いやすいインターフェースと、コンテンツを管理するための強力な編集ツールを提供します。

このチュートリアルでは、Nginxを使用してDrupalをインストールし、Ubuntu20.04でLet'sEncryptSSLを使用して保護する方法を示します。

前提条件
  • Ubuntu20.04を実行しているサーバー。
  • サーバーで指定された有効なドメイン名。
  • ルートパスワードはサーバーで構成されています。

LEMPサーバーをインストールする

まず、Nginx Webサーバー、MariaDBデータベース、PHP、およびその他の必要な拡張機能をサーバーにインストールする必要があります。次のコマンドを使用して、それらすべてをインストールできます。

apt-get install nginx mariadb-server php7.4 php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip -y

すべてのパッケージがインストールされたら、php.iniファイルを編集し、いくつかの設定を微調整します。

nano /etc/php/7.4/fpm/php.ini

次の行を変更します:

short_open_tag = On 
cgi.fix_pathinfo=0
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 300
date.timezone = America/Chicago

終了したら、ファイルを保存して閉じます。

MariaDBデータベースを構成する

まず、MariaDBのインストールを保護し、次のコマンドを使用してMariaDBのrootパスワードを設定します。

mysql_secure_installation

以下に示すように、すべての質問に答えてください。

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
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が保護されたら、次のコマンドを使用してMariaDBシェルにログインします。

mysql -u root -p

MariaDBのrootパスワードを入力してから、Drupalのデータベースとユーザーを作成します。

MariaDB [(none)]> CREATE DATABASE drupaldb;
MariaDB [(none)]> CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'password';

次に、次のコマンドを使用して、Drupalデータベースにすべての特権を付与します。

MariaDB [(none)]> GRANT ALL ON drupaldb.* TO 'drupal'@'localhost' WITH GRANT OPTION;

次に、特権をフラッシュし、次のコマンドを使用してMariaDBシェルを終了します。

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

終了したら、次のステップに進むことができます。

Drupalをダウンロード

このチュートリアルを書いている時点で、Drupalの最新バージョンは8.8.5です。次のコマンドを使用して、NginxWebルートディレクトリにダウンロードできます。

cd /var/www/html/
wget https://ftp.drupal.org/files/projects/drupal-8.8.5.tar.gz

ダウンロードが完了したら、次のコマンドを使用してダウンロードしたファイルを抽出します。

tar -xvzf drupal-8.8.5.tar.gz

次に、抽出したディレクトリの名前をdrupalに変更し、次のコマンドを使用して適切な権限を付与します。

mv drupal-8.8.5 drupal
chown -R www-data:www-data drupal
chmod -R 755 drupal

終了したら、次のステップに進むことができます。

Drupal用にNginxを構成する

次に、次のコマンドを使用して、drupal用のNginx仮想ホスト構成ファイルを作成します。

nano /etc/nginx/sites-available/drupal

次の行を追加します:

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/drupal;
    index  index.php index.html index.htm;
    server_name  drupal.linuxbuz.com;

    client_max_body_size 100M;
    autoindex off;

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    location ~ (^|/)\. {
        return 403;
    }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    location ~ '\.php$|^/update.php' {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
}

ファイルを保存して閉じてから、サイト対応ディレクトリへのシンボリックリンクを作成します。

ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/

次に、Nginxのデフォルト構成ファイルでhash_bucket_sizeを設定します。

nano /etc/nginx/nginx.conf

http{」の下に次の行を追加します "

    server_names_hash_bucket_size 64;

ファイルを保存して閉じてから、Nginxで構文エラーがないか確認してください:

nginx -t

次の出力が得られるはずです:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

次に、Nginxサービスを再起動して、変更を適用します。

systemctl restart nginx

完了したら、次のステップに進むことができます。

SSLを暗号化してLet'sでDrupalを保護する

Let'sEncryptSSLを使用してDrupalを保護することをお勧めします。まず、次のコマンドを使用してCertbotリポジトリを追加します。

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

次に、リポジトリを更新し、次のコマンドを使用してCertbotクライアントをインストールします。

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

Certbotクライアントがインストールされたら、次のコマンドを実行して、Webサイト用のLet'sEncryptSSLをダウンロードしてインストールします。

certbot --nginx -d drupal.linuxbuz.com

以下に示すように、有効なメールアドレスを入力し、利用規約に同意するよう求められます。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y



Obtaining a new certificate
Performing the following challenges:
http-01 challenge for drupal.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/drupal

次に、HTTPトラフィックをHTTPSにリダイレクトするかどうかを選択します。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2と入力します Enterを押します インストールを完了するには:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/drupal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://drupal.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=drupal.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/drupal.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/drupal.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-08-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

この時点で、DrupalWebサイトはLet'sEncryptSSLで保護されています。

DrupalWebインストールウィザードにアクセス

次に、Webブラウザーを開き、URLhttps://drupal.linuxbuz.comを入力します。 Drupal言語選択ページにリダイレクトされます:

希望の言語を選択し、保存をクリックします および 続行 ボタン。インストールプロファイルページが表示されます:

目的のインストールプロファイルを選択し、保存をクリックします および 続行 ボタン。データベース構成ページが表示されます:

保存をクリックします および 続行 ボタン。 [サイトの構成]ページが表示されます:

サイト名、管理者ユーザー名、パスワードを入力し、保存をクリックします および 続行 ボタン。次のページのDrupalのデフォルトダッシュボードにリダイレクトされます:

結論

おめでとう!これで、Ubuntu20.04にLet'sEncryptSSLを使用してDrupalが正常にインストールおよび保護されました。これで、DrupalWebサイトのカスタマイズを開始できます。詳細については、Drupalの公式ドキュメントをご覧ください。


Ubuntu
  1. Nginxを使用してNextcloudをインストールし、Ubuntu20.04LTSでSSLを暗号化する方法

  2. Nginxを使用してMagento2をインストールし、Ubuntu20.04LTSでSSLを暗号化する方法

  3. Ubuntu20.04LTSにNginxを使用してSeafileをインストールする方法

  1. Ubuntu 15.10にNginx、PHP-FPM、SSLを使用してDrupal8をインストールする方法

  2. Ubuntu 16.04にNginx、PHP-FPM、SSLを使用してDrupal8.1をインストールする方法

  3. Ubuntu 16.04 LTSにNginx、MariaDB、HHVMを使用してWordpressをインストールする方法

  1. NGINXを使用してShopwareをインストールし、Ubuntu18.04LTSで暗号化する方法

  2. Nginxを使用してGravCMSをインストールし、Ubuntu18.04LTSに暗号化する方法

  3. Nginxを使用してX-Cartをインストールし、Ubuntu18.04LTSでSSLを暗号化する方法