Httpd服务入门知识-https(http over ssl)安全配置

                                                作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.SSL会话的简化过程

  1.   ()客户端发送可供选择的加密方式,并向服务器请求证书
  2.   ()服务器端发送证书以及选定的加密方式给客户端
  3.   ()客户端取得证书并进行证书验证
  4.     如果信任给其发证书的CA
  5.       (a)验证证书来源的合法性;用CA的公钥解密证书上数字签名
  6.       (b)验证证书的内容的合法性:完整性验证
  7.       (c)检查证书的有效期限
  8.       (d)检查证书是否被吊销
  9.       (e)证书中拥有者的名字,与访问的目标主机要一致
  10.   ()客户端生成临时会话密钥(对称密钥),并使用服务器端的公钥加密此数据发送给服务器,完成密钥交换
  11.   ()服务用此密钥加密用户请求的资源,响应给客户端
  12.  
  13.   注意:
        SSL是基于IP地址实现,单IP的主机仅可以使用一个https虚拟主机

二.使用"mode_ssl"模块实现https加密认证

1>.安装加密模块

  1. [root@node101.yinzhengjie.org.cn ~]# yum -y install mod_ssl
  2. Loaded plugins: fastestmirror
  3. Determining fastest mirrors
  4. epel/x86_64/metalink | 7.6 kB ::
  5. * base: mirrors.tuna.tsinghua.edu.cn
  6. * epel: mirrors.tuna.tsinghua.edu.cn
  7. * extras: mirrors.huaweicloud.com
  8. * updates: mirror.bit.edu.cn
  9. base | 3.6 kB ::
  10. epel | 5.3 kB ::
  11. extras | 2.9 kB ::
  12. updates | 2.9 kB ::
  13. (/): epel/x86_64/updateinfo | 1.0 MB ::
  14. (/): epel/x86_64/primary_db | 6.9 MB ::
  15. Resolving Dependencies
  16. --> Running transaction check
  17. ---> Package mod_ssl.x86_64 :2.4.-.el7.centos will be installed
  18. --> Finished Dependency Resolution
  19.  
  20. Dependencies Resolved
  21.  
  22. =====================================================================================================================
  23. Package Arch Version Repository Size
  24. =====================================================================================================================
  25. Installing:
  26. mod_ssl x86_64 :2.4.-.el7.centos base k
  27.  
  28. Transaction Summary
  29. =====================================================================================================================
  30. Install Package
  31.  
  32. Total download size: k
  33. Installed size: k
  34. Downloading packages:
  35. mod_ssl-2.4.-.el7.centos.x86_64.rpm | kB ::
  36. Running transaction check
  37. Running transaction test
  38. Transaction test succeeded
  39. Running transaction
  40. Installing : :mod_ssl-2.4.-.el7.centos.x86_64 /
  41. Verifying : :mod_ssl-2.4.-.el7.centos.x86_64 /
  42.  
  43. Installed:
  44. mod_ssl.x86_64 :2.4.-.el7.centos
  45.  
  46. Complete!
  47. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# yum -y install mod_ssl

  1. [root@node101.yinzhengjie.org.cn ~]# rpm -ql mod_ssl
  2. /etc/httpd/conf.d/ssl.conf             #配置apache httpd的加密
  3. /etc/httpd/conf.modules.d/-ssl.conf      #自动加载模块的配置文件
  4. /usr/lib64/httpd/modules/mod_ssl.so       #安装了加密模块
  5. /usr/libexec/httpd-ssl-pass-dialog
  6. /var/cache/httpd/ssl
  7. [root@node101.yinzhengjie.org.cn ~]#
  8. [root@node101.yinzhengjie.org.cn ~]#
  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/ssl.conf
  2. Listen https
  3. SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
  4. SSLSessionCache shmcb:/run/httpd/sslcache()
  5. SSLSessionCacheTimeout
  6. SSLRandomSeed startup file:/dev/urandom
  7. SSLRandomSeed connect builtin
  8. SSLCryptoDevice builtin
  9. <VirtualHost _default_:>
  10. ErrorLog logs/ssl_error_log
  11. TransferLog logs/ssl_access_log
  12. LogLevel warn
  13. SSLEngine on
  14. SSLProtocol all -SSLv2 -SSLv3
  15. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
  16. SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  17. SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
  18. <Files ~ "\.(cgi|shtml|phtml|php3?)$">
  19. SSLOptions +StdEnvVars
  20. </Files>
  21. <Directory "/var/www/cgi-bin">
  22. SSLOptions +StdEnvVars
  23. </Directory>
  24. BrowserMatch "MSIE [2-5]" \
  25. nokeepalive ssl-unclean-shutdown \
  26. downgrade-1.0 force-response-1.0
  27. CustomLog logs/ssl_request_log \
  28. "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  29. </VirtualHost>
  30. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/ssl.conf

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/ssl.conf | grep SSLCertificateFile
  2. SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# ll /etc/pki/tls/certs/localhost.crt
  5. -rw------- root root Dec : /etc/pki/tls/certs/localhost.crt
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/ssl.conf | grep SSLCertificateKeyFile
  8. SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
  9. [root@node101.yinzhengjie.org.cn ~]#
  10. [root@node101.yinzhengjie.org.cn ~]# ll /etc/pki/tls/private/localhost.key
  11. -rw------- root root Dec : /etc/pki/tls/private/localhost.key
  12. [root@node101.yinzhengjie.org.cn ~]#
  13. [root@node101.yinzhengjie.org.cn ~]# rpm -q --scripts mod_ssl
  14. postinstall scriptlet (using /bin/sh):
  15. umask
  16.  
  17. if [ -f /etc/pki/tls/private/localhost.key -o -f /etc/pki/tls/certs/localhost.crt ]; then
  18. exit
  19. fi
  20.  
  21. /usr/bin/openssl genrsa -rand /proc/apm:/proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/pro
  22. c/pci:/proc/rtc:/proc/uptime > /etc/pki/tls/private/localhost.key > /dev/null
  23. FQDN=`hostname`
  24. if [ "x${FQDN}" = "x" -o ${#FQDN} -gt ]; then
  25. FQDN=localhost.localdomain
  26. fi
  27.  
  28. cat << EOF | /usr/bin/openssl req -new -key /etc/pki/tls/private/localhost.key \
  29. -x509 -sha256 -days -set_serial $RANDOM -extensions v3_req \
  30. -out /etc/pki/tls/certs/localhost.crt >/dev/null
  31. --
  32. SomeState
  33. SomeCity
  34. SomeOrganization
  35. SomeOrganizationalUnit
  36. ${FQDN}
  37. root@${FQDN}
  38. EOF
  39. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# rpm -q --scripts mod_ssl

2>.重启服务并通过https协议访问

  1. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  2. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  3. LISTEN *: *:*
  4. LISTEN *: *:*
  5. LISTEN ::: :::*
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd
  8. [root@node101.yinzhengjie.org.cn ~]#
  9. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  10. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  11. LISTEN *: *:*
  12. LISTEN *: *:*
  13. LISTEN *: *:*
  14. LISTEN ::: :::*
  15. [root@node101.yinzhengjie.org.cn ~]#
  16. [root@node101.yinzhengjie.org.cn ~]#

  1.   如上图所示,点击"高级",弹出如下图所示的对话框。

  1.   如上图所示,点击"继续前往",之后就进入到咱们自己的https服务啦。

  1.   细心的小伙伴可能已经发现啦,我们虽然是基于主机名方式访问,理论上应该访问到的内容是FQDN所对应的虚拟主机,但内容却和我们预期的不服,这是什么原因呢?
  2.  
  3.   这是因为SSL是基于IP地址实现,单IP的主机仅可以使用一个https虚拟主机。
  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf
  2. ServerRoot "/etc/httpd"
  3. Listen
  4. Include conf.modules.d/*.conf
  5. User apache
  6. Group apache
  7. ServerAdmin root@localhost
  8. <Directory />
  9. AllowOverride none
  10. Require all denied
  11. </Directory>
  12. DocumentRoot "/var/www/html"
  13. <Directory "/var/www">
  14. AllowOverride None
  15. Require all granted
  16. </Directory>
  17. <Directory "/var/www/html">
  18. Options Indexes FollowSymLinks
  19. AllowOverride None
  20. Require all granted
  21. </Directory>
  22. <IfModule dir_module>
  23. DirectoryIndex index.html
  24. </IfModule>
  25. <Files ".ht*">
  26. Require all denied
  27. </Files>
  28. ErrorLog "logs/error_log"
  29. LogLevel warn
  30. <IfModule log_config_module>
  31. LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog
  32. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  33. <IfModule logio_module>
  34. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  35. </IfModule>
  36. CustomLog "logs/access_log" testlog
  37. </IfModule>
  38. <IfModule alias_module>
  39. ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  40. </IfModule>
  41. <Directory "/var/www/cgi-bin">
  42. AllowOverride None
  43. Options None
  44. Require all granted
  45. </Directory>
  46. <IfModule mime_module>
  47. TypesConfig /etc/mime.types
  48. AddType application/x-compress .Z
  49. AddType application/x-gzip .gz .tgz
  50. AddType text/html .shtml
  51. AddOutputFilter INCLUDES .shtml
  52. </IfModule>
  53. AddDefaultCharset UTF-8
  54. <IfModule mime_magic_module>
  55. MIMEMagicFile conf/magic
  56. </IfModule>
  57. EnableSendfile on
  58. IncludeOptional conf.d/*.conf
  59. [root@node101.yinzhengjie.org.cn ~]#
  60. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf      #查看主配置文件内容

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep ServerRoot
  2. ServerRoot "/etc/httpd"
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep IncludeOptional
  5. IncludeOptional conf.d/*.conf
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/virtualHost.conf
  8. <VirtualHost "*:80">
  9. DocumentRoot "/var/www/html/asite"
  10. ServerName "www.a.com"       
  11. <Directory "/var/www/html/asite">
  12. Require all granted
  13. </Directory>
  14. CustomLog "/var/log/httpd/access_asite_log" testlog
  15. </VirtualHost>
  16.  
  17. <VirtualHost "*:80">
  18. DocumentRoot "/var/www/html/bsite"
  19. ServerName "www.b.org"
  20. <Directory "/var/www/html/bsite">
  21. Require all granted
  22. </Directory>
  23. CustomLog "/var/log/httpd/access_bsite_log" testlog
  24. </VirtualHost>
  25.  
  26. <VirtualHost "*:80">
  27. DocumentRoot "/var/www/html/csite"
  28. ServerName "www.c.net"
  29. <Directory "/var/www/html/csite">
  30. Require all granted
  31. </Directory>
  32. CustomLog "/var/log/httpd/access_csite_log" testlog
  33. </VirtualHost>
  34. [root@node101.yinzhengjie.org.cn ~]#
  35. [root@node101.yinzhengjie.org.cn ~]# httpd -t
  36. Syntax OK
  37. [root@node101.yinzhengjie.org.cn ~]#
  38. [root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
  39. [root@node101.yinzhengjie.org.cn ~]#
  40. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  41. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  42. LISTEN 0 128 *:80 *:*
  43. LISTEN 0 128 *:22 *:*
  44. LISTEN 0 128 :::22 :::*
  45. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/virtualHost.conf

  1. [root@node101.yinzhengjie.org.cn ~]# cat /var/www/html/asite/index.html
  2. <h1>www.a.com</h1>
  3. [root@node101.yinzhengjie.org.cn ~]#
  4. [root@node101.yinzhengjie.org.cn ~]# cat /var/www/html/bsite/index.html
  5. <h1>www.b.org</h1>
  6. [root@node101.yinzhengjie.org.cn ~]#
  7. [root@node101.yinzhengjie.org.cn ~]# cat /var/www/html/csite/index.html
  8. <h1>www.c.net</h1>
  9. [root@node101.yinzhengjie.org.cn ~]#
  10. [root@node101.yinzhengjie.org.cn ~]# cat /var/www/html/index.html             #不难发现,上面的试验结果是通过访问虚拟主机的方式,但内容均被响应成该文件啦~这是由于https不支持多个虚拟主机~
  11. <h1>尹正杰到此一游</h1>
  12. [root@node101.yinzhengjie.org.cn ~]#

 

三.window安装证书(上面的试验案例总是提示证书不安全,咱们为了让它绝对安全可以手动让其安装)

1>.如下图所示,点击"证书"

2>.点击证书对话框的"详细信息"菜单并点击"复制到文件"

3>.如下图所示,点击"下一步"

4>.如下图所示,继续点击"下一步"

5>.保存证书,并点击"下一步"

6>.如下图所示,点击"完成"后,导出证书成功

7>.双击导出的证书文件,会弹出如下所示的对话框,并点击"安装证书"

8>.如下图所示,选择"本地计算机",并点击"下一步"

  1.   如上图所示,有两个选项,如果咱们选择的是"本地计算机",在删除时该证书时比较麻烦,因此我们推荐使用默认的选项,即"当前用户",如下图所示,点击继续。

9>.如下图所示,点击"浏览"并选择"受信任的根证书颁发机构"后,再点击"下一步"

10>.如下图所示,点击"完成"

11>.成功完成证书导入

  1.   如上图所示,肯能会弹出这样的对话框,点击"是"即可完成导入。

 

四.删除导入的证书

1>.如下图所示,进入谷歌浏览器"设置"界面,并点击"高级"

2>.如下图所示,点击"管理证书"

3>.如下图所示,选择对应的证书并删除。

  1.   如上图所示,如果在安装证书的时候选择的是"本地计算机",则发现删除时很麻烦,无法选中删除按钮哟~
  2.  
  3.   如下图所示,如果在安装证书时选择的是默认"当前用户",则可以选择"删除按钮"

五.通过自建CA证书实现https加密认证

1>.创建私有CA证书签名

  1. [root@node101.yinzhengjie.org.cn ~]# yum -y install tree
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.tuna.tsinghua.edu.cn
  5. * epel: mirrors.tuna.tsinghua.edu.cn
  6. * extras: mirrors.huaweicloud.com
  7. * updates: mirror.bit.edu.cn
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package tree.x86_64 :1.6.-.el7 will be installed
  11. --> Finished Dependency Resolution
  12.  
  13. Dependencies Resolved
  14.  
  15. =====================================================================================================================
  16. Package Arch Version Repository Size
  17. =====================================================================================================================
  18. Installing:
  19. tree x86_64 1.6.-.el7 base k
  20.  
  21. Transaction Summary
  22. =====================================================================================================================
  23. Install Package
  24.  
  25. Total download size: k
  26. Installed size: k
  27. Downloading packages:
  28. tree-1.6.-.el7.x86_64.rpm | kB ::
  29. Running transaction check
  30. Running transaction test
  31. Transaction test succeeded
  32. Running transaction
  33. Installing : tree-1.6.-.el7.x86_64 /
  34. Verifying : tree-1.6.-.el7.x86_64 /
  35.  
  36. Installed:
  37. tree.x86_64 :1.6.-.el7
  38.  
  39. Complete!
  40. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# yum -y install tree

  1. [root@node101.yinzhengjie.org.cn ~]# cat /etc/pki/tls/openssl.cnf
  2. #
  3. # OpenSSL example configuration file.
  4. # This is mostly being used for generation of certificate requests.
  5. #
  6.  
  7. # This definition stops the following lines choking if HOME isn't
  8. # defined.
  9. HOME = .
  10. RANDFILE = $ENV::HOME/.rnd
  11.  
  12. # Extra OBJECT IDENTIFIER info:
  13. #oid_file = $ENV::HOME/.oid
  14. oid_section = new_oids
  15.  
  16. # To use this configuration file with the "-extfile" option of the
  17. # "openssl x509" utility, name here the section containing the
  18. # X.509v3 extensions to use:
  19. # extensions =
  20. # (Alternatively, use a configuration file that has only
  21. # X.509v3 extensions in its main [= default] section.)
  22.  
  23. [ new_oids ]
  24.  
  25. # We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
  26. # Add a simple OID like this:
  27. # testoid1=1.2.3.4
  28. # Or use config file substitution like this:
  29. # testoid2=${testoid1}.5.6
  30.  
  31. # Policies used by the TSA examples.
  32. tsa_policy1 = 1.2.3.4.
  33. tsa_policy2 = 1.2.3.4.5.6
  34. tsa_policy3 = 1.2.3.4.5.7
  35.  
  36. ####################################################################
  37. [ ca ]
  38. default_ca = CA_default # The default ca section
  39.  
  40. ####################################################################
  41. [ CA_default ]
  42.  
  43. dir = /etc/pki/CA # Where everything is kept
  44. certs = $dir/certs # Where the issued certs are kept
  45. crl_dir = $dir/crl # Where the issued crl are kept
  46. database = $dir/index.txt # database index file.
  47. #unique_subject = no # Set to 'no' to allow creation of
  48. # several ctificates with same subject.
  49. new_certs_dir = $dir/newcerts # default place for new certs.
  50.  
  51. certificate = $dir/cacert.pem # The CA certificate
  52. serial = $dir/serial # The current serial number
  53. crlnumber = $dir/crlnumber # the current crl number
  54. # must be commented out to leave a V1 CRL
  55. crl = $dir/crl.pem # The current CRL
  56. private_key = $dir/private/cakey.pem# The private key
  57. RANDFILE = $dir/private/.rand # private random number file
  58.  
  59. x509_extensions = usr_cert # The extentions to add to the cert
  60.  
  61. # Comment out the following two lines for the "traditional"
  62. # (and highly broken) format.
  63. name_opt = ca_default # Subject Name options
  64. cert_opt = ca_default # Certificate field options
  65.  
  66. # Extension copying option: use with caution.
  67. # copy_extensions = copy
  68.  
  69. # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
  70. # so this is commented out by default to leave a V1 CRL.
  71. # crlnumber must also be commented out to leave a V1 CRL.
  72. # crl_extensions = crl_ext
  73.  
  74. default_days = # how long to certify for
  75. default_crl_days= # how long before next CRL
  76. default_md = sha256 # use SHA- by default
  77. preserve = no # keep passed DN ordering
  78.  
  79. # A few difference way of specifying how similar the request should look
  80. # For type CA, the listed attributes must be the same, and the optional
  81. # and supplied fields are just that :-)
  82. policy = policy_match
  83.  
  84. # For the CA policy
  85. [ policy_match ]
  86. countryName = match
  87. stateOrProvinceName = match
  88. organizationName = match
  89. organizationalUnitName = optional
  90. commonName = supplied
  91. emailAddress = optional
  92.  
  93. # For the 'anything' policy
  94. # At this point in time, you must list all acceptable 'object'
  95. # types.
  96. [ policy_anything ]
  97. countryName = optional
  98. stateOrProvinceName = optional
  99. localityName = optional
  100. organizationName = optional
  101. organizationalUnitName = optional
  102. commonName = supplied
  103. emailAddress = optional
  104.  
  105. ####################################################################
  106. [ req ]
  107. default_bits =
  108. default_md = sha256
  109. default_keyfile = privkey.pem
  110. distinguished_name = req_distinguished_name
  111. attributes = req_attributes
  112. x509_extensions = v3_ca # The extentions to add to the self signed cert
  113.  
  114. # Passwords for private keys if not present they will be prompted for
  115. # input_password = secret
  116. # output_password = secret
  117.  
  118. # This sets a mask for permitted string types. There are several options.
  119. # default: PrintableString, T61String, BMPString.
  120. # pkix : PrintableString, BMPString (PKIX recommendation before )
  121. # utf8only: only UTF8Strings (PKIX recommendation after ).
  122. # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
  123. # MASK:XXXX a literal mask value.
  124. # WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
  125. string_mask = utf8only
  126.  
  127. # req_extensions = v3_req # The extensions to add to a certificate request
  128.  
  129. [ req_distinguished_name ]
  130. countryName = Country Name ( letter code)
  131. countryName_default = XX
  132. countryName_min =
  133. countryName_max =
  134.  
  135. stateOrProvinceName = State or Province Name (full name)
  136. #stateOrProvinceName_default = Default Province
  137.  
  138. localityName = Locality Name (eg, city)
  139. localityName_default = Default City
  140.  
  141. .organizationName = Organization Name (eg, company)
  142. .organizationName_default = Default Company Ltd
  143.  
  144. # we can do this but it is not needed normally :-)
  145. #.organizationName = Second Organization Name (eg, company)
  146. #.organizationName_default = World Wide Web Pty Ltd
  147.  
  148. organizationalUnitName = Organizational Unit Name (eg, section)
  149. #organizationalUnitName_default =
  150.  
  151. commonName = Common Name (eg, your name or your server\'s hostname)
  152. commonName_max =
  153.  
  154. emailAddress = Email Address
  155. emailAddress_max =
  156.  
  157. # SET-ex3 = SET extension number
  158.  
  159. [ req_attributes ]
  160. challengePassword = A challenge password
  161. challengePassword_min =
  162. challengePassword_max =
  163.  
  164. unstructuredName = An optional company name
  165.  
  166. [ usr_cert ]
  167.  
  168. # These extensions are added when 'ca' signs a request.
  169.  
  170. # This goes against PKIX guidelines but some CAs do it and some software
  171. # requires this to avoid interpreting an end user certificate as a CA.
  172.  
  173. basicConstraints=CA:FALSE
  174.  
  175. # Here are some examples of the usage of nsCertType. If it is omitted
  176. # the certificate can be used for anything *except* object signing.
  177.  
  178. # This is OK for an SSL server.
  179. # nsCertType = server
  180.  
  181. # For an object signing certificate this would be used.
  182. # nsCertType = objsign
  183.  
  184. # For normal client use this is typical
  185. # nsCertType = client, email
  186.  
  187. # and for everything including object signing:
  188. # nsCertType = client, email, objsign
  189.  
  190. # This is typical in keyUsage for a client certificate.
  191. # keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  192.  
  193. # This will be displayed in Netscape's comment listbox.
  194. nsComment = "OpenSSL Generated Certificate"
  195.  
  196. # PKIX recommendations harmless if included in all certificates.
  197. subjectKeyIdentifier=hash
  198. authorityKeyIdentifier=keyid,issuer
  199.  
  200. # This stuff is for subjectAltName and issuerAltname.
  201. # Import the email address.
  202. # subjectAltName=email:copy
  203. # An alternative to produce certificates that aren't
  204. # deprecated according to PKIX.
  205. # subjectAltName=email:move
  206.  
  207. # Copy subject details
  208. # issuerAltName=issuer:copy
  209.  
  210. #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
  211. #nsBaseUrl
  212. #nsRevocationUrl
  213. #nsRenewalUrl
  214. #nsCaPolicyUrl
  215. #nsSslServerName
  216.  
  217. # This is required for TSA certificates.
  218. # extendedKeyUsage = critical,timeStamping
  219.  
  220. [ v3_req ]
  221.  
  222. # Extensions to add to a certificate request
  223.  
  224. basicConstraints = CA:FALSE
  225. keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  226.  
  227. [ v3_ca ]
  228.  
  229. # Extensions for a typical CA
  230.  
  231. # PKIX recommendation.
  232.  
  233. subjectKeyIdentifier=hash
  234.  
  235. authorityKeyIdentifier=keyid:always,issuer
  236.  
  237. # This is what PKIX recommends but some broken software chokes on critical
  238. # extensions.
  239. #basicConstraints = critical,CA:true
  240. # So we do this instead.
  241. basicConstraints = CA:true
  242.  
  243. # Key usage: this is typical for a CA certificate. However since it will
  244. # prevent it being used as an test self-signed certificate it is best
  245. # left out by default.
  246. # keyUsage = cRLSign, keyCertSign
  247.  
  248. # Some might want this also
  249. # nsCertType = sslCA, emailCA
  250.  
  251. # Include email address in subject alt name: another PKIX recommendation
  252. # subjectAltName=email:copy
  253. # Copy issuer details
  254. # issuerAltName=issuer:copy
  255.  
  256. # DER hex encoding of an extension: beware experts only!
  257. # obj=DER::
  258. # Where 'obj' is a standard or added object
  259. # You can even override a supported extension:
  260. # basicConstraints= critical, DER:::::FF
  261.  
  262. [ crl_ext ]
  263.  
  264. # CRL extensions.
  265. # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
  266.  
  267. # issuerAltName=issuer:copy
  268. authorityKeyIdentifier=keyid:always
  269.  
  270. [ proxy_cert_ext ]
  271. # These extensions should be added when creating a proxy certificate
  272.  
  273. # This goes against PKIX guidelines but some CAs do it and some software
  274. # requires this to avoid interpreting an end user certificate as a CA.
  275.  
  276. basicConstraints=CA:FALSE
  277.  
  278. # Here are some examples of the usage of nsCertType. If it is omitted
  279. # the certificate can be used for anything *except* object signing.
  280.  
  281. # This is OK for an SSL server.
  282. # nsCertType = server
  283.  
  284. # For an object signing certificate this would be used.
  285. # nsCertType = objsign
  286.  
  287. # For normal client use this is typical
  288. # nsCertType = client, email
  289.  
  290. # and for everything including object signing:
  291. # nsCertType = client, email, objsign
  292.  
  293. # This is typical in keyUsage for a client certificate.
  294. # keyUsage = nonRepudiation, digitalSignature, keyEncipherment
  295.  
  296. # This will be displayed in Netscape's comment listbox.
  297. nsComment = "OpenSSL Generated Certificate"
  298.  
  299. # PKIX recommendations harmless if included in all certificates.
  300. subjectKeyIdentifier=hash
  301. authorityKeyIdentifier=keyid,issuer
  302.  
  303. # This stuff is for subjectAltName and issuerAltname.
  304. # Import the email address.
  305. # subjectAltName=email:copy
  306. # An alternative to produce certificates that aren't
  307. # deprecated according to PKIX.
  308. # subjectAltName=email:move
  309.  
  310. # Copy subject details
  311. # issuerAltName=issuer:copy
  312.  
  313. #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
  314. #nsBaseUrl
  315. #nsRevocationUrl
  316. #nsRenewalUrl
  317. #nsCaPolicyUrl
  318. #nsSslServerName
  319.  
  320. # This really needs to be in place for it to be a proxy certificate.
  321. proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:,policy:foo
  322.  
  323. ####################################################################
  324. [ tsa ]
  325.  
  326. default_tsa = tsa_config1 # the default TSA section
  327.  
  328. [ tsa_config1 ]
  329.  
  330. # These are used by the TSA reply generation only.
  331. dir = ./demoCA # TSA root directory
  332. serial = $dir/tsaserial # The current serial number (mandatory)
  333. crypto_device = builtin # OpenSSL engine to use for signing
  334. signer_cert = $dir/tsacert.pem # The TSA signing certificate
  335. # (optional)
  336. certs = $dir/cacert.pem # Certificate chain to include in reply
  337. # (optional)
  338. signer_key = $dir/private/tsakey.pem # The TSA private key (optional)
  339.  
  340. default_policy = tsa_policy1 # Policy if request did not specify it
  341. # (optional)
  342. other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
  343. digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory)
  344. accuracy = secs:, millisecs:, microsecs: # (optional)
  345. clock_precision_digits = # number of digits after dot. (optional)
  346. ordering = yes # Is ordering defined for timestamps?
  347. # (optional, default: no)
  348. tsa_name = yes # Must the TSA name be included in the reply?
  349. # (optional, default: no)
  350. ess_cert_id_chain = no # Must the ESS cert id chain be included?
  351. # (optional, default: no)
  352. [root@node101.yinzhengjie.org.cn ~]#
  353. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# cat /etc/pki/tls/openssl.cnf                                        #证书私钥文件需要遵守该配置文件的关键设置

  1. [root@node101.yinzhengjie.org.cn ~]# tree /etc/pki/CA/
  2. /etc/pki/CA/
  3. ├── certs
  4. ├── crl
  5. ├── newcerts
  6. └── private
  7. directories, files
  8. [root@node101.yinzhengjie.org.cn ~]#
  9. [root@node101.yinzhengjie.org.cn ~]# (umask ;openssl genrsa -out /etc/pki/CA/private/cakey.pem )        #创建证书的私钥文件
  10. Generating RSA private key, bit long modulus
  11. .....+++
  12. .........+++
  13. e is (0x10001)
  14. [root@node101.yinzhengjie.org.cn ~]#
  15. [root@node101.yinzhengjie.org.cn ~]# tree /etc/pki/CA/
  16. /etc/pki/CA/
  17. ├── certs
  18. ├── crl
  19. ├── newcerts
  20. └── private
  21. └── cakey.pem
  22. directories, file
  23. [root@node101.yinzhengjie.org.cn ~]#
  24. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# (umask 066;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)                  #创建证书的私钥文件

  1. [root@node101.yinzhengjie.org.cn ~]# tree /etc/pki/CA/
  2. /etc/pki/CA/
  3. ├── certs
  4. ├── crl
  5. ├── newcerts
  6. └── private
  7. └── cakey.pem
  8.  
  9. directories, file
  10. [root@node101.yinzhengjie.org.cn ~]#
  11. [root@node101.yinzhengjie.org.cn ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem      #生成自签名证书
  12. You are about to be asked to enter information that will be incorporated
  13. into your certificate request.
  14. What you are about to enter is what is called a Distinguished Name or a DN.
  15. There are quite a few fields but you can leave some blank
  16. For some fields there will be a default value,
  17. If you enter '.', the field will be left blank.
  18. -----
  19. Country Name ( letter code) [XX]:CN
  20. State or Province Name (full name) []:beijing
  21. Locality Name (eg, city) [Default City]:beijing
  22. Organization Name (eg, company) [Default Company Ltd]:www.yinzhengjie.org.cn
  23. Organizational Unit Name (eg, section) []:devops
  24. Common Name (eg, your name or your server's hostname) []:ca.yinzhengjie.org.cn
  25. Email Address []:
  26. [root@node101.yinzhengjie.org.cn ~]#
  27. [root@node101.yinzhengjie.org.cn ~]# tree /etc/pki/CA/
  28. /etc/pki/CA/
  29. ├── cacert.pem
  30. ├── certs
  31. ├── crl
  32. ├── newcerts
  33. └── private
  34. └── cakey.pem
  35.  
  36. directories, files
  37. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem      #生成自签名证书

  1. [root@node101.yinzhengjie.org.cn ~]# touch /etc/pki/CA/index.txt      #数据库索引文件,创建出来就好,后面位整数签名时程序会自动往里面写入数据
  2. [root@node101.yinzhengjie.org.cn ~]#
  3. [root@node101.yinzhengjie.org.cn ~]# echo > /etc/pki/CA/serial     #指定下一个申请整数的编号
  4. [root@node101.yinzhengjie.org.cn ~]#
  5. [root@node101.yinzhengjie.org.cn ~]# tree /etc/pki/CA/
  6. /etc/pki/CA/
  7. ├── cacert.pem
  8. ├── certs
  9. ├── crl
  10. ├── index.txt
  11. ├── newcerts
  12. ├── private
  13.    └── cakey.pem
  14. └── serial
  15.  
  16. directories, files
  17. [root@node101.yinzhengjie.org.cn ~]#

2>.为httpd服务器申请数字证书

  1. [root@node101.yinzhengjie.org.cn ~]# mkdir /etc/httpd/conf.d/ssl                                #创建存放证书相关文件目录
  2. [root@node101.yinzhengjie.org.cn ~]#
  3. [root@node101.yinzhengjie.org.cn ~]# cd /etc/httpd/conf.d/ssl/
  4. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  5. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]# (umask ;openssl genrsa -out httpd.key )        #生成私钥文件
  6. Generating RSA private key, bit long modulus
  7. .................++++++
  8. ............++++++
  9. e is (0x10001)
  10. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  11. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]# openssl req -new -key httpd.key -out httpd.csr        #生成证书申请文件,下面标记红色的3个字符串必须和CA证书一样(国家,省,公司)哟~
  12. You are about to be asked to enter information that will be incorporated
  13. into your certificate request.
  14. What you are about to enter is what is called a Distinguished Name or a DN.
  15. There are quite a few fields but you can leave some blank
  16. For some fields there will be a default value,
  17. If you enter '.', the field will be left blank.
  18. -----
  19. Country Name ( letter code) [XX]:CN
  20. State or Province Name (full name) []:beijing
  21. Locality Name (eg, city) [Default City]:beijing
  22. Organization Name (eg, company) [Default Company Ltd]:www.yinzhengjie.org.cn
  23. Organizational Unit Name (eg, section) []:beiguozhuanyehu
  24. Common Name (eg, your name or your server's hostname) []:*.yinzhengjie.org.cn
  25. Email Address []:
  26.  
  27. Please enter the following 'extra' attributes
  28. to be sent with your certificate request
  29. A challenge password []:
  30. An optional company name []:
  31. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  32. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]# ll
  33. total
  34. -rw-r--r-- root root Dec : httpd.csr
  35. -rw------- root root Dec : httpd.key
  36. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  37. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]# cd /etc/pki/CA/
  38. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  39. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# openssl ca -in /etc/httpd/conf.d/ssl/httpd.csr -out certs/httpd.crt -days 100      #颁发证书,指定证书的有效期为100天,默认是365天。
  40. Using configuration from /etc/pki/tls/openssl.cnf
  41. Check that the request matches the signature
  42. Signature ok
  43. Certificate Details:
  44. Serial Number: (0x1)
  45. Validity
  46. Not Before: Dec :: GMT
  47. Not After : Mar :: GMT
  48. Subject:
  49. countryName = CN
  50. stateOrProvinceName = beijing
  51. organizationName = www.yinzhengjie.org.cn
  52. organizationalUnitName = beiguozhuanyehu
  53. commonName = *.yinzhengjie.org.cn
  54. X509v3 extensions:
  55. X509v3 Basic Constraints:
  56. CA:FALSE
  57. Netscape Comment:
  58. OpenSSL Generated Certificate
  59. X509v3 Subject Key Identifier:
  60. BE:F9:E0:ED::3F:B4:E1:B5:9A::3B:D7::6F:::3E:8F:9F
  61. X509v3 Authority Key Identifier:
  62. keyid:FF::D8:A2:::C4:::::E2:9B:7E::::1F::5F
  63.  
  64. Certificate is to be certified until Mar :: GMT ( days)
  65. Sign the certificate? [y/n]:y
  66.  
  67. out of certificate requests certified, commit? [y/n]y
  68. Write out database with new entries
  69. Data Base Updated
  70. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  71. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# tree
  72. .
  73. ├── cacert.pem
  74. ├── certs
  75. │   └── httpd.crt
  76. ├── crl
  77. ├── index.txt
  78. ├── index.txt.attr
  79. ├── index.txt.old
  80. ├── newcerts
  81. │   └── .pem
  82. ├── private
  83. │   └── cakey.pem
  84. ├── serial
  85. └── serial.old
  86.  
  87. directories, files
  88. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  89. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# cat index.txt      #这是我们之前手动创建的文件,发现内容被更新了,存放的是证书的相关信息
  90. V 200318110006Z unknown /C=CN/ST=beijing/O=www.yinzhengjie.org.cn/OU=beiguozhuanyehu/CN=*.yinzhengjie.org.cn
  91. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  92. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# cat serial        #由于我们已经申请了一个证书,因此下一个申请证书的编号会自动加1。
  93.  
  94. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# cp certs/httpd.crt /etc/httpd/conf.d/ssl/    #证书文件拷贝到咱们自定义httpd存放证书文件达的目录中
  95. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  96. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# cp cacert.pem /etc/httpd/conf.d/ssl/       #将ca的证书文件也拷贝到咱们自定义httpd存放证书文件的目录中
  97. [root@node101.yinzhengjie.org.cn /etc/pki/CA]#
  98. [root@node101.yinzhengjie.org.cn /etc/pki/CA]# cd /etc/httpd/conf.d/ssl/
  99. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  100. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]# ll
  101. total
  102. -rw-r--r-- root root Dec : cacert.pem
  103. -rw-r--r-- root root Dec : httpd.crt
  104. -rw-r--r-- 1 root root 700 Dec 9 18:57 httpd.csr          #由于证书申请已经完成,因此该文件的存在意义不大了,我们可以删除掉它。
  105. -rw------- root root Dec : httpd.key
  106. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#
  107. [root@node101.yinzhengjie.org.cn /etc/httpd/conf.d/ssl]#

3>.编辑httpd服务器的配置文件

  1. [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/ssl
  2. total
  3. -rw-r--r-- root root Dec : cacert.pem
  4. -rw-r--r-- root root Dec : httpd.crt
  5. -rw-r--r-- root root Dec : httpd.csr
  6. -rw------- root root Dec : httpd.key
  7. [root@node101.yinzhengjie.org.cn ~]#
  8. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/ssl.conf
  9. Listen https
  10. SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
  11. SSLSessionCache shmcb:/run/httpd/sslcache()
  12. SSLSessionCacheTimeout
  13. SSLRandomSeed startup file:/dev/urandom
  14. SSLRandomSeed connect builtin
  15. SSLCryptoDevice builtin
  16. <VirtualHost _default_:>
  17. ErrorLog logs/ssl_error_log
  18. TransferLog logs/ssl_access_log
  19. LogLevel warn
  20. SSLEngine on
  21. SSLProtocol all -SSLv2 -SSLv3
  22. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
  23. SSLCertificateFile /etc/httpd/conf.d/ssl/httpd.crt
  24. SSLCertificateKeyFile /etc/httpd/conf.d/ssl/httpd.key
  25. SSLCACertificateFile /etc/httpd/conf.d/ssl/cacert.pem
  26. <Files ~ "\.(cgi|shtml|phtml|php3?)$">
  27. SSLOptions +StdEnvVars
  28. </Files>
  29. <Directory "/var/www/cgi-bin">
  30. SSLOptions +StdEnvVars
  31. </Directory>
  32. BrowserMatch "MSIE [2-5]" \
  33. nokeepalive ssl-unclean-shutdown \
  34. downgrade-1.0 force-response-1.0
  35. CustomLog logs/ssl_request_log \
  36. "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  37. </VirtualHost>
  38. [root@node101.yinzhengjie.org.cn ~]#
  39. [root@node101.yinzhengjie.org.cn ~]#

4>通过https协议访问咱们的httpd服务器

5>.如下图所示,查看证书的"常规"信息

6>.从服务器端下载证书文件

7>.更改证书文件后缀

8>.双击证书文件,并点击"安装证书",后续步骤上面有提到过,这里就忽略啦

9>.客户端测试

  1. [root@node101.yinzhengjie.org.cn ~]#
  2. [root@node101.yinzhengjie.org.cn ~]# openssl s_client -connect www.yinzhengjie.org.cn: -CAfile /etc/httpd/conf.d/ssl/cacert.pem
  3. CONNECTED()
  4. depth= C = CN, ST = beijing, L = beijing, O = www.yinzhengjie.org.cn, OU = devops, CN = ca.yinzhengjie.org.cn
  5. verify return:
  6. depth= C = CN, ST = beijing, O = www.yinzhengjie.org.cn, OU = beiguozhuanyehu, CN = *.yinzhengjie.org.cn
  7. verify return:
  8. ---
  9. Certificate chain
  10. s:/C=CN/ST=beijing/O=www.yinzhengjie.org.cn/OU=beiguozhuanyehu/CN=*.yinzhengjie.org.cn
  11. i:/C=CN/ST=beijing/L=beijing/O=www.yinzhengjie.org.cn/OU=devops/CN=ca.yinzhengjie.org.cn
  12. s:/C=CN/ST=beijing/L=beijing/O=www.yinzhengjie.org.cn/OU=devops/CN=ca.yinzhengjie.org.cn
  13. i:/C=CN/ST=beijing/L=beijing/O=www.yinzhengjie.org.cn/OU=devops/CN=ca.yinzhengjie.org.cn
  14. ---
  15. Server certificate
  16. -----BEGIN CERTIFICATE-----
  17. MIIDbzCCAlegAwIBAgIBATANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCQ04x
  18. EDAOBgNVBAgMB2JlaWppbmcxEDAOBgNVBAcMB2JlaWppbmcxHzAdBgNVBAoMFnd3
  19. dy55aW56aGVuZ2ppZS5vcmcuY24xDzANBgNVBAsMBmRldm9wczEeMBwGA1UEAwwV
  20. Y2EueWluemhlbmdqaWUub3JnLmNuMB4XDTE5MTIwOTExMDAwNloXDTIwMDMxODEx
  21. MDAwNloweTELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB2JlaWppbmcxHzAdBgNVBAoM
  22. Fnd3dy55aW56aGVuZ2ppZS5vcmcuY24xGDAWBgNVBAsMD2JlaWd1b3podWFueWVo
  23. dTEdMBsGA1UEAwwUKi55aW56aGVuZ2ppZS5vcmcuY24wgZ8wDQYJKoZIhvcNAQEB
  24. BQADgY0AMIGJAoGBALJMIc3emzFJRelMJMF1nab8KwEYxBkqk3Iwu9rJ/UEYC7Wg
  25. RP1wx9IIpXXO6L98rDmLfcEMS6388KDQZglcJ5Sf7Qch6ilV3hru5gYXjoIals+W
  26. 82nB1rDhS2ivXqv6wu7gIMnOjkukhM1nOjYewsBF1iWN4GtcvgW8kV5K0IDRAgMB
  27. AAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJh
  28. dGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBS++eDteD+04bWaITvXcm8wNz6PnzAf
  29. BgNVHSMEGDAWgBT/AdiiVnfEkyMnQuKbfkRoFR8pXzANBgkqhkiG9w0BAQsFAAOC
  30. AQEAYYivZaQe8vz1WYZdmJZ/1O1y0OSH/VwJAAxKdWZNFISh0SxRljnW1tOpItmP
  31. RXmAOcHlRzomBj6vjvyYlRrTvxa+7MIMR6EcGcu7aVAnNIYWxVP+Y6fHma/5Na7W
  32. Sj8XHkXNmT7xBlc8ykUWX5w9ZfwpPnly38EXSXywVUYDH9bt7Mzdi1Q4UywP2ysu
  33. 0AhrPJ0UdNVEGI2yGhroiVsHjHyUTj4HKwEZIm/uQWcjWdwlLzB79ilGF97B4tdw
  34. bGhYWANlvi2teyxg4O0hJQTTmv1ad5Fr306HNUZPnfZaG8IDxBigkv1+WCjodbap
  35. /25vDTjHnKbnV+zUg8MyTfeq3g==
  36. -----END CERTIFICATE-----
  37. subject=/C=CN/ST=beijing/O=www.yinzhengjie.org.cn/OU=beiguozhuanyehu/CN=*.yinzhengjie.org.cn
  38. issuer=/C=CN/ST=beijing/L=beijing/O=www.yinzhengjie.org.cn/OU=devops/CN=ca.yinzhengjie.org.cn
  39. ---
  40. No client certificate CA names sent
  41. Peer signing digest: SHA512
  42. Server Temp Key: ECDH, P-, bits
  43. ---
  44. SSL handshake has read bytes and written bytes
  45. ---
  46. New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
  47. Server public key is bit
  48. Secure Renegotiation IS supported
  49. Compression: NONE
  50. Expansion: NONE
  51. No ALPN negotiated
  52. SSL-Session:
  53. Protocol : TLSv1.
  54. Cipher : ECDHE-RSA-AES256-GCM-SHA384
  55. Session-ID: 96CA50CB30562B491E8555CDF41EE662C66CB9AB7A1A535692BDDABED4513DE9
  56. Session-ID-ctx:
  57. Master-Key: B52FCF27C5ED19ED984D5BB1044C8D408AF9F102A69EBF5F4B57B06ACE2342796BA27761100F511892801F57DBBE5B42
  58. Key-Arg : None
  59. Krb5 Principal: None
  60. PSK identity: None
  61. PSK identity hint: None
  62. TLS session ticket lifetime hint: (seconds)
  63. TLS session ticket:
  64. - 6f a1 -b7 9c 3c 9f cf )o..V).r.&$.<.c.
  65. - aa 1d f6 b2 e4 db- b7 ee b4 6d c0 W.......t"...mt.
  66. - fe a6 6f d6 d6 7d 1c- 0f 2f ...o..}.C..../
  67. - fe 7c ef 4c 3e - 3a ac 5d 5b ...|.L>....:.g][
  68. - e5 ac e8 d7 d9 d9 -f7 d1 e0 a2 4e c1 ..(....a....IN.
  69. - 1d a4 bd 5d a5-ab 1a e4 8e be ....s]C.........
  70. - fb f9 be-fc fa a4 db ad ..g.......V....p
  71. - db f2 - e1 a2 e7 ab d.....hEI....%..
  72. - dc 9f 5d 7b-a9 4c d8 3c 9b Qt..y.]{.L.Q<#Y.
  73. - f9 1c 7d bb-ce a9 8d 6e ca ...$.}......n#B.
  74. 00a0 - b2 d7 b2 c8 9f 9f f4-be a3 d7 e4 d9 e6 ..Q............c
  75. 00b0 - c1 c5 f2 e2 d1-ef f3 4a ab be ..F..B...E..J4..
  76.  
  77. Start Time:
  78. Timeout : (sec)
  79. Verify return code: (ok)
  80. ---

[root@node101.yinzhengjie.org.cn ~]# openssl s_client -connect www.yinzhengjie.org.cn:443 -CAfile                  #使用openssl命令访问服务端

  1. [root@node101.yinzhengjie.org.cn ~]# curl -k https://www.yinzhengjie.org.cn --cacert /etc/httpd/conf.d/ssl/cacert.pem         #忽略证书检查访问网页
  2. <h1>尹正杰到此一游</h1>
  3. [root@node101.yinzhengjie.org.cn ~]#

六.将http请求转发至https的URL

1>.http重定向https概述

  1. 重定向
  2.   Redirect [status] URL-path URL

  3. status状态:
  4.   Permanent 返回永久重定向状态码
  5.   Temp:返回临时重定向状态码302. 此为默认值

  6. 示例:
  7.   Redirect temp / https://www.yinzhengjie.org.cn/

2>.查看京东公司的重定向策略

  1. [root@node101.yinzhengjie.org.cn ~]# curl -I http://www.360buy.com          #查看京东的早期域名
  2. HTTP/1.1 Moved Permanently                               #这是永久性的跳转,这意味着这家公司可能后期不使用该域名啦~
  3. Server: nginx
  4. Date: Mon, Dec :: GMT
  5. Content-Type: text/html
  6. Content-Length:
  7. Connection: keep-alive
  8. Location: http://www.jd.com/
  9. Age:
  10. Via: http/1.1 ORI-BJ-CT-YF-PCS- (jcs [cSsSfU]), https/1.1 ORI-CLOUD-YF-MIX- (jcs [cHs f ]), http/1.1 JN-UNI--MIX- (jcs [cRs f ])
  11. Access-Control-Allow-Origin: *
  12. Timing-Allow-Origin: *
  13. X-Trace: ------;------;------;------
  14.  
  15. [root@node101.yinzhengjie.org.cn ~]#
  16. [root@node101.yinzhengjie.org.cn ~]#
  17. [root@node101.yinzhengjie.org.cn ~]# curl -I http://www.jd.com        #查看目前京东的域名,注意咱们使用的并不是https哟~
  18. HTTP/1.1 Moved Temporarily                           #我们发现他会把http临时重定向到https上去。
  19. Server: nginx
  20. Date: Mon, Dec :: GMT
  21. Content-Type: text/html
  22. Content-Length:
  23. Connection: keep-alive
  24. Location: https://www.jd.com/
  25. Access-Control-Allow-Origin: *
  26. Timing-Allow-Origin: *
  27. X-Trace: ------
  28. Strict-Transport-Security: max-age=
  29.  
  30. [root@node101.yinzhengjie.org.cn ~]#

3>.修改httpd的配置文件

  1. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf
  2. ServerRoot "/etc/httpd"
  3. Listen
  4. Include conf.modules.d/*.conf
  5. User apache
  6. Group apache
  7. ServerAdmin root@localhost
  8. <Directory />
  9. AllowOverride none
  10. Require all denied
  11. </Directory>
  12. DocumentRoot "/var/www/html"
  13. <Directory "/var/www">
  14. AllowOverride None
  15. Require all granted
  16. </Directory>
  17. <Directory "/var/www/html">
  18. Options Indexes FollowSymLinks
  19. AllowOverride None
  20. Require all granted
  21. </Directory>
  22. <IfModule dir_module>
  23. DirectoryIndex index.html
  24. </IfModule>
  25. <Files ".ht*">
  26. Require all denied
  27. </Files>
  28. ErrorLog "logs/error_log"
  29. LogLevel warn
  30. <IfModule log_config_module>
  31. LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog
  32. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  33. <IfModule logio_module>
  34. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  35. </IfModule>
  36. CustomLog "logs/access_log" testlog
  37. </IfModule>
  38. <IfModule alias_module>
  39. ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  40. </IfModule>
  41. <Directory "/var/www/cgi-bin">
  42. AllowOverride None
  43. Options None
  44. Require all granted
  45. </Directory>
  46. <IfModule mime_module>
  47. TypesConfig /etc/mime.types
  48. AddType application/x-compress .Z
  49. AddType application/x-gzip .gz .tgz
  50. AddType text/html .shtml
  51. AddOutputFilter INCLUDES .shtml
  52. </IfModule>
  53. AddDefaultCharset UTF-8
  54. <IfModule mime_magic_module>
  55. MIMEMagicFile conf/magic
  56. </IfModule>
  57. EnableSendfile on
  58. IncludeOptional conf.d/*.conf
  59. Redirect temp / https://www.yinzhengjie.org.cn/            #没错,就是它有重定向功能。
  60. [root@node101.yinzhengjie.org.cn ~]#
  61. [root@node101.yinzhengjie.org.cn ~]# httpd -t
  62. Syntax OK
  63. [root@node101.yinzhengjie.org.cn ~]#
  64. [root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
  65. [root@node101.yinzhengjie.org.cn ~]#
  66. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  67. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  68. LISTEN 0 128 *:80 *:*
  69. LISTEN 0 128 *:22 *:*
  70. LISTEN 0 128 *:443 *:*
  71. LISTEN 0 128 :::22 :::*
  72. [root@node101.yinzhengjie.org.cn ~]#

4>.使用客户端访问测试发现问题

  1. [root@node101.yinzhengjie.org.cn ~]# curl -kIL http://www.yinzhengjie.org.cn
  2. HTTP/1.1 Found
  3. Date: Mon, Dec :: GMT
  4. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  5. Location: https://www.yinzhengjie.org.cn/
  6. Content-Type: text/html; charset=iso--
  7.  
  8. HTTP/1.1 Found
  9. Date: Mon, Dec :: GMT
  10. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  11. Location: https://www.yinzhengjie.org.cn/
  12. Content-Type: text/html; charset=iso--
  13.  
  14. HTTP/1.1 Found
  15. Date: Mon, Dec :: GMT
  16. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  17. Location: https://www.yinzhengjie.org.cn/
  18. Content-Type: text/html; charset=iso--
  19.  
  20. HTTP/1.1 Found
  21. Date: Mon, Dec :: GMT
  22. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  23. Location: https://www.yinzhengjie.org.cn/
  24. Content-Type: text/html; charset=iso--
  25.  
  26. HTTP/1.1 Found
  27. Date: Mon, Dec :: GMT
  28. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  29. Location: https://www.yinzhengjie.org.cn/
  30. Content-Type: text/html; charset=iso--
  31.  
  32. HTTP/1.1 Found
  33. Date: Mon, Dec :: GMT
  34. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  35. Location: https://www.yinzhengjie.org.cn/
  36. Content-Type: text/html; charset=iso--
  37.  
  38. HTTP/1.1 Found
  39. Date: Mon, Dec :: GMT
  40. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  41. Location: https://www.yinzhengjie.org.cn/
  42. Content-Type: text/html; charset=iso--
  43.  
  44. HTTP/1.1 Found
  45. Date: Mon, Dec :: GMT
  46. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  47. Location: https://www.yinzhengjie.org.cn/
  48. Content-Type: text/html; charset=iso--
  49.  
  50. HTTP/1.1 Found
  51. Date: Mon, Dec :: GMT
  52. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  53. Location: https://www.yinzhengjie.org.cn/
  54. Content-Type: text/html; charset=iso--
  55.  
  56. HTTP/1.1 Found
  57. Date: Mon, Dec :: GMT
  58. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  59. Location: https://www.yinzhengjie.org.cn/
  60. Content-Type: text/html; charset=iso--
  61.  
  62. HTTP/1.1 Found
  63. Date: Mon, Dec :: GMT
  64. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  65. Location: https://www.yinzhengjie.org.cn/
  66. Content-Type: text/html; charset=iso--
  67.  
  68. HTTP/1.1 Found
  69. Date: Mon, Dec :: GMT
  70. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  71. Location: https://www.yinzhengjie.org.cn/
  72. Content-Type: text/html; charset=iso--
  73.  
  74. HTTP/1.1 Found
  75. Date: Mon, Dec :: GMT
  76. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  77. Location: https://www.yinzhengjie.org.cn/
  78. Content-Type: text/html; charset=iso--
  79.  
  80. HTTP/1.1 Found
  81. Date: Mon, Dec :: GMT
  82. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  83. Location: https://www.yinzhengjie.org.cn/
  84. Content-Type: text/html; charset=iso--
  85.  
  86. HTTP/1.1 Found
  87. Date: Mon, Dec :: GMT
  88. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  89. Location: https://www.yinzhengjie.org.cn/
  90. Content-Type: text/html; charset=iso--
  91.  
  92. HTTP/1.1 Found
  93. Date: Mon, Dec :: GMT
  94. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  95. Location: https://www.yinzhengjie.org.cn/
  96. Content-Type: text/html; charset=iso--
  97.  
  98. HTTP/1.1 Found
  99. Date: Mon, Dec :: GMT
  100. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  101. Location: https://www.yinzhengjie.org.cn/
  102. Content-Type: text/html; charset=iso--
  103.  
  104. HTTP/1.1 Found
  105. Date: Mon, Dec :: GMT
  106. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  107. Location: https://www.yinzhengjie.org.cn/
  108. Content-Type: text/html; charset=iso--
  109.  
  110. HTTP/1.1 Found
  111. Date: Mon, Dec :: GMT
  112. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  113. Location: https://www.yinzhengjie.org.cn/
  114. Content-Type: text/html; charset=iso--
  115.  
  116. HTTP/1.1 Found
  117. Date: Mon, Dec :: GMT
  118. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  119. Location: https://www.yinzhengjie.org.cn/
  120. Content-Type: text/html; charset=iso--
  121.  
  122. HTTP/1.1 Found
  123. Date: Mon, Dec :: GMT
  124. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  125. Location: https://www.yinzhengjie.org.cn/
  126. Content-Type: text/html; charset=iso--
  127.  
  128. HTTP/1.1 Found
  129. Date: Mon, Dec :: GMT
  130. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  131. Location: https://www.yinzhengjie.org.cn/
  132. Content-Type: text/html; charset=iso--
  133.  
  134. HTTP/1.1 Found
  135. Date: Mon, Dec :: GMT
  136. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  137. Location: https://www.yinzhengjie.org.cn/
  138. Content-Type: text/html; charset=iso--
  139.  
  140. HTTP/1.1 Found
  141. Date: Mon, Dec :: GMT
  142. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  143. Location: https://www.yinzhengjie.org.cn/
  144. Content-Type: text/html; charset=iso--
  145.  
  146. HTTP/1.1 Found
  147. Date: Mon, Dec :: GMT
  148. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  149. Location: https://www.yinzhengjie.org.cn/
  150. Content-Type: text/html; charset=iso--
  151.  
  152. HTTP/1.1 Found
  153. Date: Mon, Dec :: GMT
  154. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  155. Location: https://www.yinzhengjie.org.cn/
  156. Content-Type: text/html; charset=iso--
  157.  
  158. HTTP/1.1 Found
  159. Date: Mon, Dec :: GMT
  160. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  161. Location: https://www.yinzhengjie.org.cn/
  162. Content-Type: text/html; charset=iso--
  163.  
  164. HTTP/1.1 Found
  165. Date: Mon, Dec :: GMT
  166. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  167. Location: https://www.yinzhengjie.org.cn/
  168. Content-Type: text/html; charset=iso--
  169.  
  170. HTTP/1.1 Found
  171. Date: Mon, Dec :: GMT
  172. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  173. Location: https://www.yinzhengjie.org.cn/
  174. Content-Type: text/html; charset=iso--
  175.  
  176. HTTP/1.1 Found
  177. Date: Mon, Dec :: GMT
  178. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  179. Location: https://www.yinzhengjie.org.cn/
  180. Content-Type: text/html; charset=iso--
  181.  
  182. HTTP/1.1 Found
  183. Date: Mon, Dec :: GMT
  184. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  185. Location: https://www.yinzhengjie.org.cn/
  186. Content-Type: text/html; charset=iso--
  187.  
  188. HTTP/1.1 Found
  189. Date: Mon, Dec :: GMT
  190. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  191. Location: https://www.yinzhengjie.org.cn/
  192. Content-Type: text/html; charset=iso--
  193.  
  194. HTTP/1.1 Found
  195. Date: Mon, Dec :: GMT
  196. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  197. Location: https://www.yinzhengjie.org.cn/
  198. Content-Type: text/html; charset=iso--
  199.  
  200. HTTP/1.1 Found
  201. Date: Mon, Dec :: GMT
  202. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  203. Location: https://www.yinzhengjie.org.cn/
  204. Content-Type: text/html; charset=iso--
  205.  
  206. HTTP/1.1 Found
  207. Date: Mon, Dec :: GMT
  208. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  209. Location: https://www.yinzhengjie.org.cn/
  210. Content-Type: text/html; charset=iso--
  211.  
  212. HTTP/1.1 Found
  213. Date: Mon, Dec :: GMT
  214. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  215. Location: https://www.yinzhengjie.org.cn/
  216. Content-Type: text/html; charset=iso--
  217.  
  218. HTTP/1.1 Found
  219. Date: Mon, Dec :: GMT
  220. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  221. Location: https://www.yinzhengjie.org.cn/
  222. Content-Type: text/html; charset=iso--
  223.  
  224. HTTP/1.1 Found
  225. Date: Mon, Dec :: GMT
  226. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  227. Location: https://www.yinzhengjie.org.cn/
  228. Content-Type: text/html; charset=iso--
  229.  
  230. HTTP/1.1 Found
  231. Date: Mon, Dec :: GMT
  232. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  233. Location: https://www.yinzhengjie.org.cn/
  234. Content-Type: text/html; charset=iso--
  235.  
  236. HTTP/1.1 Found
  237. Date: Mon, Dec :: GMT
  238. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  239. Location: https://www.yinzhengjie.org.cn/
  240. Content-Type: text/html; charset=iso--
  241.  
  242. HTTP/1.1 Found
  243. Date: Mon, Dec :: GMT
  244. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  245. Location: https://www.yinzhengjie.org.cn/
  246. Content-Type: text/html; charset=iso--
  247.  
  248. HTTP/1.1 Found
  249. Date: Mon, Dec :: GMT
  250. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  251. Location: https://www.yinzhengjie.org.cn/
  252. Content-Type: text/html; charset=iso--
  253.  
  254. HTTP/1.1 Found
  255. Date: Mon, Dec :: GMT
  256. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  257. Location: https://www.yinzhengjie.org.cn/
  258. Content-Type: text/html; charset=iso--
  259.  
  260. HTTP/1.1 Found
  261. Date: Mon, Dec :: GMT
  262. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  263. Location: https://www.yinzhengjie.org.cn/
  264. Content-Type: text/html; charset=iso--
  265.  
  266. HTTP/1.1 Found
  267. Date: Mon, Dec :: GMT
  268. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  269. Location: https://www.yinzhengjie.org.cn/
  270. Content-Type: text/html; charset=iso--
  271.  
  272. HTTP/1.1 Found
  273. Date: Mon, Dec :: GMT
  274. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  275. Location: https://www.yinzhengjie.org.cn/
  276. Content-Type: text/html; charset=iso--
  277.  
  278. HTTP/1.1 Found
  279. Date: Mon, Dec :: GMT
  280. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  281. Location: https://www.yinzhengjie.org.cn/
  282. Content-Type: text/html; charset=iso--
  283.  
  284. HTTP/1.1 Found
  285. Date: Mon, Dec :: GMT
  286. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  287. Location: https://www.yinzhengjie.org.cn/
  288. Content-Type: text/html; charset=iso--
  289.  
  290. HTTP/1.1 Found
  291. Date: Mon, Dec :: GMT
  292. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  293. Location: https://www.yinzhengjie.org.cn/
  294. Content-Type: text/html; charset=iso--
  295.  
  296. HTTP/1.1 Found
  297. Date: Mon, Dec :: GMT
  298. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  299. Location: https://www.yinzhengjie.org.cn/
  300. Content-Type: text/html; charset=iso--
  301.  
  302. HTTP/1.1 Found
  303. Date: Mon, Dec :: GMT
  304. Server: Apache/2.4. (CentOS) OpenSSL/1.0.2k-fips
  305. Location: https://www.yinzhengjie.org.cn/
  306. Content-Type: text/html; charset=iso--
  307.  
  308. curl: () Maximum () redirects followed
  309. [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# curl -kIL http://www.yinzhengjie.org.cn

5>.引入HSTS(HTTP Strict Transport Security)解决上面递归跳转的问题 

  1. HSTS:HTTP Strict Transport Security
  2.   服务器端配置支持HSTS后,会在给浏览器返回的HTTP首部中携带HSTS字段。浏览器获取到该信息后,会将所有HTTP访问请求在内部做307跳转到HTTPS。而无需任何网络过程
  3.  
  4. HSTS preload list
  5.   Chrome浏览器中的HSTS预载入列表,在该列表中的网站,使用Chrome浏览器访问时,会自动转换成HTTPSFirefoxSafariEdge浏览器也会采用这个列表
  6.  
  7. 实现重定向示例:
  8. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf
  9. ServerRoot "/etc/httpd"
  10. Listen
  11. Include conf.modules.d/*.conf
  12. User apache
  13. Group apache
  14. ServerAdmin root@localhost
  15. <Directory />
  16. AllowOverride none
  17. Require all denied
  18. </Directory>
  19. DocumentRoot "/var/www/html"
  20. <Directory "/var/www">
  21. AllowOverride None
  22. Require all granted
  23. </Directory>
  24. <Directory "/var/www/html">
  25. Options Indexes FollowSymLinks
  26. AllowOverride None
  27. Require all granted
  28. </Directory>
  29. <IfModule dir_module>
  30. DirectoryIndex index.html
  31. </IfModule>
  32. <Files ".ht*">
  33. Require all denied
  34. </Files>
  35. ErrorLog "logs/error_log"
  36. LogLevel warn
  37. <IfModule log_config_module>
  38. LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog
  39. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  40. <IfModule logio_module>
  41. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  42. </IfModule>
  43. CustomLog "logs/access_log" testlog
  44. </IfModule>
  45. <IfModule alias_module>
  46. ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  47. </IfModule>
  48. <Directory "/var/www/cgi-bin">
  49. AllowOverride None
  50. Options None
  51. Require all granted
  52. </Directory>
  53. <IfModule mime_module>
  54. TypesConfig /etc/mime.types
  55. AddType application/x-compress .Z
  56. AddType application/x-gzip .gz .tgz
  57. AddType text/html .shtml
  58. AddOutputFilter INCLUDES .shtml
  59. </IfModule>
  60. AddDefaultCharset UTF-8
  61. <IfModule mime_magic_module>
  62. MIMEMagicFile conf/magic
  63. </IfModule>
  64. EnableSendfile on
  65. IncludeOptional conf.d/*.conf
  66. RewriteEngine on                                #只需要将上面的"Redirect temp / https://www.yinzhengjie.org.cn/"语句换成当前行和下一行这两行就能解决递归重定向的问题。
  67. RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=302]
  68. [root@node101.yinzhengjie.org.cn ~]#
  69. [root@node101.yinzhengjie.org.cn ~]# httpd -t
  70. Syntax OK
  71. [root@node101.yinzhengjie.org.cn ~]#
  72. [root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
  73. [root@node101.yinzhengjie.org.cn ~]#
  74. [root@node101.yinzhengjie.org.cn ~]# ss -ntl
  75. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  76. LISTEN 0 128 *:80 *:*
  77. LISTEN 0 128 *:22 *:*
  78. LISTEN 0 128 *:443 *:*
  79. LISTEN 0 128 :::22 :::*
  80. [root@node101.yinzhengjie.org.cn ~]#

  1. 实现HSTS示例:(生产环境建议启用该功能)
  2. [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf
  3. ServerRoot "/etc/httpd"
  4. Listen
  5. Include conf.modules.d/*.conf
  6. User apache
  7. Group apache
  8. ServerAdmin root@localhost
  9. <Directory />
  10. AllowOverride none
  11. Require all denied
  12. </Directory>
  13. DocumentRoot "/var/www/html"
  14. <Directory "/var/www">
  15. AllowOverride None
  16. Require all granted
  17. </Directory>
  18. <Directory "/var/www/html">
  19. Options Indexes FollowSymLinks
  20. AllowOverride None
  21. Require all granted
  22. </Directory>
  23. <IfModule dir_module>
  24. DirectoryIndex index.html
  25. </IfModule>
  26. <Files ".ht*">
  27. Require all denied
  28. </Files>
  29. ErrorLog "logs/error_log"
  30. LogLevel warn
  31. <IfModule log_config_module>
  32. LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" testlog
  33. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  34. <IfModule logio_module>
  35. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  36. </IfModule>
  37. CustomLog "logs/access_log" testlog
  38. </IfModule>
  39. <IfModule alias_module>
  40. ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
  41. </IfModule>
  42. <Directory "/var/www/cgi-bin">
  43. AllowOverride None
  44. Options None
  45. Require all granted
  46. </Directory>
  47. <IfModule mime_module>
  48. TypesConfig /etc/mime.types
  49. AddType application/x-compress .Z
  50. AddType application/x-gzip .gz .tgz
  51. AddType text/html .shtml
  52. AddOutputFilter INCLUDES .shtml
  53. </IfModule>
  54. AddDefaultCharset UTF-8
  55. <IfModule mime_magic_module>
  56. MIMEMagicFile conf/magic
  57. </IfModule>
  58. EnableSendfile on
  59. IncludeOptional conf.d/*.conf
  60. Header always set Strict-Transport-Security "max-age=31536000"          #看这里,它就是启用了HSTS功能,下面两行是实现https到https重定向的~
  61. RewriteEngine on
  62. RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=302]
  63. [root@node101.yinzhengjie.org.cn ~]#
  64. [root@node101.yinzhengjie.org.cn ~]# httpd -t
  65. Syntax OK
  66. [root@node101.yinzhengjie.org.cn ~]#
  67. [root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
  68. [root@node101.yinzhengjie.org.cn ~]#
  69. [root@node101.yinzhengjie.org.cn ~]# curl -I http://www.yinzhengjie.org.cn  #仔细观察此行的输出部分和上图的输出部分
  70. HTTP/1.1 302 Found
  71. Date: Mon, 09 Dec 2019 12:59:52 GMT
  72. Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
  73. Strict-Transport-Security: max-age=31536000                     #不难发现,这里有相应的HSTS相关参数,表示支持HSTS支持的时长为1年,单位默认为秒。
  74. Location: https://www.yinzhengjie.org.cn/
  75. Content-Type: text/html; charset=iso-8859-1
  76.  
  77. [root@node101.yinzhengjie.org.cn ~]#

Httpd服务入门知识-https(http over ssl)安全配置的更多相关文章

  1. Httpd服务入门知识-正向代理和反向代理

    Httpd服务入门知识-正向代理和反向代理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.正向代理和反向代理 启用反向代理 ProxyPass "/" &q ...

  2. Httpd服务入门知识-Httpd服务常见配置案例之日志设定

    Httpd服务入门知识-Httpd服务常见配置案例之日志设定 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.日志类型 [root@node101.yinzhengjie.org ...

  3. Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Options  1>.OPTIONS指 ...

  4. Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.基于用户的访问控制概述 认证质询: WWW-Auth ...

  5. Httpd服务入门知识-Httpd服务安装

    Httpd服务入门知识-Httpd服务安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Httpd概述 1>.Httpd介绍 20世纪90年代初,国家超级计算机应用中心 ...

  6. Httpd服务入门知识-http协议版本,工作机制及http服务器应用扫盲篇

    Httpd服务入门知识-http协议版本,工作机制及http服务器应用扫盲篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Internet与中国 Internet最早来源于美 ...

  7. Httpd服务入门知识-使用mod_deflate模块压缩页面优化传输速度

    Httpd服务入门知识-使用mod_deflate模块压缩页面优化传输速度 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.mod_deflate模块概述 mod_deflate ...

  8. Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机

    Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.虚拟主机实现方案 1>.Apache httpd 有三种实现虚 ...

  9. Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面

    Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.status功能概述 status页 ...

随机推荐

  1. python3 获取日期时间

    #!/usr/bin/python3 import time # 格式化成2016-- ::39形式 print (time.strftime("%Y-%m-%d %H:%M:%S" ...

  2. 微信小程序之简单记账本开发记录(七)

    记账本已经可以实现添加和删除的功能 现在只需要将上述步骤重复一遍便可将另一个界面做出来. 大体上已制作完成,如果在细节上有变动会在这一篇更新 总体来说,这个作业让我对微信小程序的开发有了更多地认识,大 ...

  3. centos git编译

    1. 下载git源码 https://git-scm.com 2. 根据文档一步步操作 https://git-scm.com/book/en/v2/Getting-Started-Installin ...

  4. 2018的Java

    少用复制黏贴 程序员很多时候都习惯复制黏贴,这里复制一点,那里复制一点,拼拼凑凑的搞出了一段代码.这是一种常态,毕竟没有必要重复造轮子,在开发的时候,讲究的是效率,讲究速度,有时候也是不得不这样做.但 ...

  5. 一张MGR切换的图,不解释

  6. pytest新版本(5.3.2)中收集测试方法规则不支持以test结尾的方法

    pytest新版本(5.3.2)中收集测试方法规则不支持以test结尾的方法,只能命名为以test开头,否则不能识别到

  7. linux_权限小练习

    下面是解释: 当前# root用户, ls列出列表 mkdir 新建目录 赋予目录744权限      对others来说是  r--  只可读 touch 新建在目录下的同名文件 赋予文件600权限 ...

  8. linux下杀掉某用户所有进程

    直接删除用户,提示该用户下还有进程,以下两种方法可解决: 1.结束所有username的进程(如果提示没有该命令,那么用下面方法) killall -u username 2.杀死某一用户下的所有进程 ...

  9. Topshelf 搭建 Windows 服务

    Topshelf 是一个用来部署基于.NET Framework 开发的服务的框架.简化服务创建于部署过程,并且支持控制台应用程序部署为服务.本文基于 .net core 控制台应用程序部署为服务(. ...

  10. Delphi BusinessSkinForm使用说明

    1.先放bsBusinessSkinForm.bsSkinData.bsStoredSkin各一个到窗体上 2.修改bsBusinessSkinForm的SkinData属性为bsSkinData1 ...