GNU/Linux >> Linux の 問題 >  >> Cent OS

Rocky Linux /Centos8でLetsencryptを使用してNginxを保護する方法

これは、インターネットセキュリティ研究グループ(ISRG)によって開発され、すべての主要なブラウザによって信頼されています。これは、証明書の作成、検証、署名、実装、および安全なWebサイトの証明書の更新のプロセスを自動化するために使用されます。

証明書の有効期間は90日間のみであるため、手動で更新するか、自動更新システムを設定する必要があります。

Let's Encryptは、Apache、Nginx、Plex、およびHAproxyの自動認証発行をサポートします。このガイドではnginxについて説明します。

関連コンテンツ

  • Ubuntu20.04でLetsencryptを使用してNginxを保護する方法
  • Rocky Linux / Centos 8にNginx、WordPress、Mysql8をインストールしてセットアップする方法
  • Ubuntu20.04でNginxをインストールして仮想ホストを構成する方法

前提条件:

  • インターネットアクセスとパブリックIPを備えたCentOS8サーバー
  • サーバーを指すDNSを持つ有効なドメイン名
  • Centos8サーバーへのルートアクセス

CertbotLet'sEncryptクライアントのインストール

ssh [email protected] -p portを使用してサーバーにログインします :

ssh [email protected]

すべてのパッケージを最新の利用可能なバージョンに更新します。

sudo dnf update -y

Nginxをインストールする

sudo dnf install -y nginx

nginxを起動して有効にします

systemctl start nginx
systemctl enable nginx

このために、nginx構成を作成しましょう:
更新されたNginx構成:

server {
    listen 80;
    server_tokens off;
    client_max_body_size 10M;
    server_name site1.citizix.com;

    access_log /var/log/nginx/site1.citizix.com/access.log;
    error_log /var/log/nginx/site1.citizix.com/error.log;
    ignore_invalid_headers off;

    ## Deny illegal Host headers
    if ($host !~* ^(site1.citizix.com)$ ) {
        return 444;
    }

    root /var/www/site1.citizix.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Scheme $scheme;
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

}

Certbotクライアントをインストールする

Certbotは、WebサイトのLet’sEncryptSSL証明書を取得および更新するプロセスを簡素化するために使用されるコマンドラインツールです。

sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx

Firewalldを使用している場合、ファイアウォールでhttpとhttpsを有効にします:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

sudo firewall-cmd --reload

# Verify
sudo firewall-cmd --permanent --list-all

証明書の取得

nginxを停止します:

sudo systemctl stop nginx
sudo certbot --nginx --non-interactive --agree-tos --email [email protected] -d site1.citizix.com

出力

# sudo certbot --nginx --non-interactive --agree-tos --email [email protected] -d site1.citizix.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Account registered.
Requesting a certificate for site1.citizix.com
Performing the following challenges:
http-01 challenge for site1.citizix.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/site1.citizix.com.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/site1.citizix.com.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://site1.citizix.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/site1.citizix.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/site1.citizix.com/privkey.pem
   Your certificate will expire on 2021-11-05. 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

nginxを開始します:

sudo systemctl start nginx

更新されたNginx構成:

server {
    server_tokens off;
    client_max_body_size 10M;
    server_name site1.citizix.com;

    access_log /var/log/nginx/site1.citizix.com/access.log;
    error_log /var/log/nginx/site1.citizix.com/error.log;
    ignore_invalid_headers off;

    ## Deny illegal Host headers
    if ($host !~* ^(site1.citizix.com)$ ) {
        return 444;
    }

    root /var/www/site1.citizix.com;

    location / {
        proxy_pass http://127.0.0.1:8096;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Scheme $scheme;
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/site1.citizix.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/site1.citizix.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = site1.citizix.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name site1.citizix.com;
    return 404; # managed by Certbot
}

Cent OS
  1. Rocky Linux / Alma Linux /CentOS8にFreeIPAクライアントをインストールする方法

  2. Centos8からRockyLinux8に移行する方法

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

  1. Rocky Linux /Centos8にMysql8をインストールする方法

  2. Rocky Linux / Alma Linux /CentOS8にErlangをインストールする方法

  3. CentOS6にLinuxDashをインストールする方法

  1. CentOS7にNginxを使用してphpMyAdminをインストールする方法

  2. CentOS7にNginxを使用してSuiteCRMをインストールする方法

  3. CentOS7にNginxでMediaWikiをインストールする方法