配置HTTPS

環境為CentOS 7.3、httpd2.4.6

一 搭建證書

CA 主機為192.168.29.3

client主機為 192.168.29.100

1 生成私鑰

[root@centos7 ~]# (umask 077 ; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
Generating RSA private key, 4096 bit long modulus
.....................++
...........................................................................................................................................................................................++
e is 65537 (0x10001)

2 生成自簽證書

[root@centos7 ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365
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]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Company
Organizational Unit Name (eg, section) []:OPS
Common Name (eg, your name or your server's hostname) []:www.test.com
Email Address []:
[root@centos7 ~]#

3 為CA提供所需的目錄及文件

(1)所需目錄,如果無,則創建

/etc/pki/CA/certs/

/etc/pki/CA/crl/

/etc/pki/CA/newcerts/

(2)所需文件

[root@centos7 ~]# touch /etc/pki/CA/serial #序列號文件

[root@centos7 ~]# touch /etc/pki/CA/index.txt #數據庫文件

(3)

[root@centos7 ~]# echo 01 > /etc/pki/CA/serial #維護ca的序列號

4 在client上進行如下操作

(1)創建放置公鑰私鑰的文件夾

[root@CentOS7 ~]# mkdir /etc/httpd/ssl

(2)生成自己的私鑰

[root@CentOS7 ~]# (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)

Generating RSA private key, 2048 bit long modulus

…………………………………+++

……………………………..+++

e is 65537 (0x10001)

[root@CentOS7 ~]#

(3)請CA為自己生成公鑰

[root@CentOS7 ~]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
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]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Company
Organizational Unit Name (eg, section) []:OPS
Common Name (eg, your name or your server's hostname) []:www.test.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

(4)把生成的公鑰發送給CA

[root@CentOS7 ~]# scp /etc/httpd/ssl/httpd.csr root@192.168.29.3:/tmp/
The authenticity of host '192.168.29.3 (192.168.29.3)' can't be established.
ECDSA key fingerprint is f2:2e:89:a2:8d:22:22:9c:a9:f8:c9:19:18:d3:b6:c4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.29.3' (ECDSA) to the list of known hosts.
root@192.168.29.3's password:
httpd.csr 100% 1005 1.0KB/s 00:00

5 在CA主機上為client簽證

[root@centos7 ~]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Jun 3 02:54:23 2017 GMT
Not After : Jun 3 02:54:23 2018 GMT
Subject:
countryName = CN
stateOrProvinceName = BeiJing
organizationName = Company
organizationalUnitName = OPS
commonName = www.test.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
5D:A9:5A:90:29:F3:3A:7F:76:BE:21:78:14:80:E5:FB:5E:03:D8:D9
X509v3 Authority Key Identifier:
keyid:9E:1E:F3:84:4D:D0:79:E2:BD:DD:A8:50:29:6C:BA:0C:21:60:CA:96
Certificate is to be certified until Jun 3 02:54:23 2018 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

6 把簽署的證書發給client

[root@centos7 ~]# scp /etc/pki/CA/certs/httpd.crt root@192.168.29.100:/etc/httpd/ssl/
The authenticity of host '192.168.29.100 (192.168.29.100)' can't be established.
ECDSA key fingerprint is 32:16:f3:2d:78:65:9f:a0:31:6c:dc:b9:24:e7:5a:8f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.29.100' (ECDSA) to the list of known hosts.
root@192.168.29.100's password:
httpd.crt 100% 5711 5.6KB/s 00:00

二 HTTPS配置

7 安裝mod_ssl模塊

[root@CentOS7 ~]# yum install mod_ssl -y

8 修改配置文件/etc/httpd/conf.d/ssl.conf

DocumentRoot "/data/https"
ServerName www.test.com:443
<Directory "data/https">
AllowOverride None
Require all granted
</Directory>
SSLCertificateFile /etc/httpd/ssl/httpd.crt

SSLCertificateKeyFile /etc/httpd/ssl/httpd.crt

注意:

并修該/etc/httpd/ssl/httpd.crt、/etc/httpd/ssl/httpd.crt兩個文件的屬性,確保apach為可讀就行,當然也可放在默認文件夾下,就不需要修改權限了。

[root@CentOS7 ~]#chmod +r /etc/httpd/ssl/httpd.key

9 檢查語法

[root@CentOS7 ~]# httpd -t

Syntax OK

10 修給默認頁面

[root@CentOS7 ~]# echo “www.test.com” > /data/https/index.html

11 啟動http服務

[root@CentOS7 ~]# systemctl start httpd.service

12 把CA 的自簽證書傳到桌面

[root@centos7 ~]# sz /etc/pki/CA/cacert.pem

改名為cacert.crt

配置HTTPS

雙擊導入IE瀏覽器

13 配置DNS解析

www.test.com 為192.168.29.100

或者 修改windows 下的C:WindowsSysteme32driversetchosts文件

192.168.29.100    www.test.com

14 打開IE瀏覽器測試

輸入https://www.test.com

配置HTTPS

好了 成功了 好用成就感呀?。?

原創文章,作者:linux is not unix,如若轉載,請注明出處:http://www.www58058.com/77675

(1)
linux is not unixlinux is not unix
上一篇 2017-06-06 19:03
下一篇 2017-06-06 20:15

相關推薦

  • Linux的簡介

    Linux的簡介 馮諾依曼體系結構 主要特點:使用存儲器,采用二進制(據說,采用二進制的靈感來源于中國的八卦,2變4,4變8…) 體系介紹:其由幾大部分組成,輸入設備,運算器,控制器,內部存儲器,外部存儲器,輸出設備。 目前,輸入設備就是指鍵盤鼠標, 運算器和控制器現在統稱CPU。其實已經內置了兩個功能。 內部存儲器就是內存,某種意義上,緩存也算…

    Linux干貨 2016-10-28
  • 8.9_Linux文本處理三劍客之sed和文本編輯利器vim的使用

    本文處理三劍客之sed的使用   什么是sed? Stream EDitor(簡稱sed), 行編輯器,一次只讀一行,只處理一行,不對源文件做處理,至輸出到屏幕上。 sed是一種流編輯器,它一次處理一行內容。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”(pattern space),接著用sed命令處理緩沖區中的內容,處理完成后,把緩…

    Linux干貨 2016-08-11
  • LVS

        Linux虛擬服務器(LVS)是基于Linux內核的操作系統的負載平衡軟件。     LVS提供了良好的可擴展性,可靠性和可服務性。 LVS項目的主要工作是開發先進的IP 負載平衡軟件(IPVS),應用級負載平衡軟件(KTCPVS)和集群管理組件。 IPVS:在…

    Linux干貨 2017-08-21
  • Linux基礎

    計算機組成和功能 按照Von Neumann的理解 [1],計算機分為以下幾部分:     輸入 (Input Device, 用于提供給計算機待處理的數據)         e.g. 鍵盤,…    &nbs…

    Linux干貨 2016-09-27
  • 位運算符及其應用

    一、C語言的六種位運算符: & 按位與 | 按位或 ^ 按位異或 ~ 取反 << 左移 >> 右移 1.   按位與運算 按位與運算符"&"是雙目運算符。     &nb…

    Linux干貨 2015-11-18
  • rpm數據庫損壞 不能使用正常使用yum的處理方法

           不知道有沒有跟我一樣的小伙伴,在使用yum安裝軟件時,發現無法正常使用yum安裝軟件包,下面出現幾句英語提示。在使用rpm時也無法正常的使用。其實 是rpm數據庫崩潰導致的 下面就簡單的介紹一下怎么回復,讓其正常的工作,很簡單幾個命了即可。 1. 出現錯誤提示,這時我們需要認真的閱讀下面的提示,不要亂找原…

    Linux干貨 2017-06-13
欧美性久久久久