GNU/Linux >> Linux の 問題 >  >> Panels >> Panels

Ubuntu20.04でLet'sEncryptを使用してNginxを保護する方法

NginxをWebサーバーとして実行しているWebサイトの保護は、Let’s Encryptを使用して行うことができます。そのため、このチュートリアルを作成しています。

Let’s Encryptは、90日間有効な無料のTLS/SSL証明書を提供する認証局です。 SSLはSecureSocketsLayerの略で、SSL証明書は、暗号化された接続とWebサイトIDの認証を可能にするデジタル証明書です。このブログ投稿では、Certbotを使用してNginxの無料SSL証明書を取得します。

Certbotを使用してUbuntu20.04に無料のLet’s Encrypt SSL証明書をインストールするのは簡単なプロセスであり、最大10分かかります。始めましょう!

前提条件
  • Ubuntu20.04の新規インストール
  • ユーザー権限:sudo権限を持つrootまたは非rootユーザー
  • 有効サーバーのIPアドレス(yourdomain.comおよびwww.yourdomain.com)を指すドメインのレコード
システムを更新する

インストールプロセスを開始する前に、システムを更新して最新のパッケージと更新を利用できるようにする必要があります。

sudo apt update -y && sudo apt upgrade -y

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

Nginx Webサーバーをインストールするには、次のコマンドを実行します。

sudo apt install nginx -y

インストールが完了したら、Nginxサービスを有効にして開始します。

sudo systemctl enable nginx && sudo systemctl start nginx

すべてがOKかどうかを確認するには、サービスのステータスを確認します。

sudo systemctl status nginx

次の出力が表示されます。

root@vps:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-02-06 19:34:56 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 322857 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 322858 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 322859 (nginx)
      Tasks: 5 (limit: 4617)
     Memory: 5.0M
     CGroup: /system.slice/nginx.service
             ├─322859 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

Nginx仮想ホストを作成

Free Let’s Encryptのインストールを続行する前に、ドメイン名を含む仮想ホストファイルを作成する必要があります。 Nginx構成ディレクトリに移動し、ファイルを作成します。

cd /etc/nginx/conf.d/ && sudo nano yourdomain.com.conf

次のコード行を貼り付けます。

server {
        listen 80;
        root /var/www/html;
        index  index.php index.html index.htm;
        server_name yourdomain.com;

        error_log /var/log/nginx/yourdomain.com_error.log;
        access_log /var/log/nginx/yourdomain.com_access.log;

        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

OKの場合は、Nginx構成構文を確認してください。

nginx -t

次の出力が表示されます。

root@vps:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
>

この出力を受け取ったら、Nginxサービスを再起動して、Webサイトにアクセスできます。

sudo systemctl restart nginx

Certbotをインストールする

現在、当社のウェブサイトはHTTPプロトコルを介して実行されています。無料のLet’s Encrypt SSL証明書をインストールすると、HTTPSプロトコルを介して当社のWebサイトが安全に実行されます。証明書の取得を開始する前に、Nginx用のpythoncertbotをインストールする必要があります。

sudo apt install certbot python3-certbot-nginx

certbotが正常にインストールされると、SSL証明書の取得に関するこのチュートリアルのメインステップに進むことができます。

SSL証明書の取得

ドメインの名前を指定してNginxプラグインを使用してcertbotを実行するには、次のコマンドを実行します。

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

このコマンドを実行した後、メールアドレス、利用規約に関する同意、メールアドレスを共有するかどうか、リダイレクトオプションなど、入力する必要のあるエントリがいくつかあります。

root@vps:~# sudo certbot --nginx -d yourdomain.com -d www.yourdomain.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: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourdomain.com
http-01 challenge for www.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf

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
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf

すべてが適切に設定されている場合、証明書がインストールされ、以下のメッセージが表示されます。

Congratulations! You have successfully enabled https://yourdomain.com and
https://www.yourdomain.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourdomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourdomain.com/privkey.pem
   Your cert will expire on 2022-05-07. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

これで、 https://yourdomain.comで安全にWebサイトにアクセスできます。

おめでとう! Ubuntu20.04サーバーでFreeLet’sEncryptSSL証明書を使用してNginxを正常に保護しました。

もちろん、SSL証明書を自分でインストールする必要はありません。また、SSD VPSホスティングサービスのいずれかを使用している場合は、エキスパートシステム管理者にSSL証明書をインストールして、ウェブサイトを保護するよう依頼するだけです。 24時間年中無休でご利用いただけます。リクエストはすぐに処理されます。

この投稿が気に入った場合は、Ubuntu20.04でLetsEncryptを使用してNginxを保護する方法について、下のボタンを使用してソーシャルネットワーク上の友達と共有するか、コメントセクションにコメントを残してください。ありがとう。


Panels
  1. Ubuntu14.04にNginxでElggをインストールする方法

  2. Ubuntu18.04にNginxでElggをインストールする方法

  3. Ubuntu20.04にNGINXと無料のLet'sEncryptSSLを使用してGiteaをインストールする方法

  1. Ubuntu18.04でLet'sEncryptを使用してNginxを保護する-その方法は?

  2. Ubuntu20.04でLetsencryptを使用してNginxを保護する方法

  3. Ubuntu18.04にNginxでJoomlaをインストールする方法

  1. Ubuntu 20.04/18.04でLetsEncryptを使用してNginxを保護する方法

  2. Ubuntu18.04でLetsEncryptを使用してNginxを保護する

  3. Apacheを使用してUbuntu20.04にLet’sEncryptをインストールする方法