ホームページ  >  記事  >  運用・保守  >  Apache で自己署名証明書を作成してインストールする方法

Apache で自己署名証明書を作成してインストールする方法

不言
不言オリジナル
2019-03-30 15:15:283396ブラウズ

SSL は、ユーザーと Web サーバー間の安全な通信に役立ちます。証明書は、ハッカーに対して脆弱にならないように、公衆回線を介して送信されるデータを暗号化します。自己署名証明書は無料で使用できますが、クレジット カードや Paypal 情報などの機密データを使用する場合など、運用環境では使用されません。この記事では、Linux システム上の Apache サーバーに自己署名証明書を作成してインストールする方法を紹介します。

Apache で自己署名証明書を作成してインストールする方法

ステップ 1: mod_ssl パッケージをインストールする

SSL 証明書を設定するには、mod_ssl がシステムにインストールされていることを確認してください。まだインストールされていない場合は、次のコマンドを使用してインストールする必要があります。さらに、openssl パッケージをインストールして証明書を作成します。

$ sudo apt-get install openssl          # Debian based systems 
$ sudo yum install mod_ssl openssl      # Redhat / CentOS systems 
$ sudo dnf install mod_ssl openssl      # Fedora 22+ systems

ステップ 2: 自己署名証明書を作成する

mod_ssl と openssl をインストールした後、次のコマンドを使用してドメインの自己署名証明書を作成します。

$ sudo mkdir -p /etc/pki/tls/certs
$ sudo cd /etc/pki/tls/certs

次に、SSL 証明書を作成します。

$ sudo openssl req -x509 -nodes -newkey rsa:2048 -keyout example.com.key -out example.com.crt

出力

Generating a 2048 bit RSA private key
....................................+++
...................................+++
writing new private key to 'example.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]: IN
State or Province Name (full name) []: Delhi
Locality Name (eg, city) [Default City]: Delhi
Organization Name (eg, company) [Default Company Ltd]: TecAdmin
Organizational Unit Name (eg, section) []: blog
Common Name (eg, your name or your server's hostname) []: www.example.com
Email Address []: admin@example.com

上記のコマンドは、現在のディレクトリに SSL キー ファイル example.com.key と証明書ファイル example を作成します。 .com.crt。

ステップ 3: Apache に自己署名証明書をインストールする

これで、自己署名 SSL 証明書とキー ファイルが完成しました。次に、Apache SSL 構成ファイルを編集し、以下の手順に従って編集/更新します。

Apache 仮想ホスト構成:

<VirtualHost _default_:443>
    ServerAdmin admin@example.com
    ServerName www.example.com
    ServerAlias example.com

    DocumentRoot /var/www/html

    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/example.com.crt
    SSLCertificateKeyFile /etc/pki/tls/certs/example.com.key
</VirtualHost>

ステップ 4: Apache の再起動

上記のコマンドでエラーが表示されない場合は、Apache サービスを再起動してください。 。

$ sudo systemctl restart apache2       # Debian based systems   
$ sudo systemctl restart httpd         # Redhat based systems

ステップ 5: https

を使用して Web サイトをテストする 最後に、https を使用して Web ブラウザーでサイトを開きます。 HTTPS を使用してサイトにアクセスするには、ポート 443 を開く必要があります。

 https://www.example.com

自己署名証明書を使用すると、ブラウザに警告メッセージが表示されますが、このメッセージは無視してください。

以上がApache で自己署名証明書を作成してインストールする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。