设为首页 收藏本站
查看: 1055|回复: 0

[经验分享] 基于SSL的Apache配置

[复制链接]
发表于 2018-11-22 12:55:40 | 显示全部楼层 |阅读模式
  HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。该系统提供了身份验证与加密通讯方法,现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。
  
  

  SSL会话建立过程:
1.      客户端和服务器端进行交互,协商加密方式进行秘钥交互
2.      服务器端给客户端发送证书
3.      双方生成对称秘钥,并使用服务器的公钥加密后发给服务器
4.      客户端就可以访问服务器端的网页,用户的请求也以加密方式传送
  

  下面就来详细介绍基于SSL的Apache的配置

  使用rpm安装的httpd不支持ssl,需要安装mod_ssl 模块就可以支持SSL
  
  Yum install mod_ssl
  Vim /etc/httpd/ conf.d/ssl.conf
  LoadModule ssl_module modules/mod_ssl.so
  Listen 443
  AddType application/x-x509-ca-cert  .crt 证书列表
  AddType application/x-pkcs7-crl  ./crl 证书吊销列表
  SLPassPhraseDialog  builtin 内部会话建立机制
  SSLSessionCache        shmcb:/var/cache/mod_ssl/scache(512000) 会话缓存
  SSLSessionCacheTimeout  300 缓存超时时间
  SSLRandomSeed startupfile:/dev/urandom  256 随机数的种子
  SSLRandomSeed connect builtin
  SSLCryptoDevice builtin SSL的加密设备
  只能为一个基于主机名的虚拟主机提供SSL
  
  DocumentRoot "/vhosts/magedu.com"
  ServerName www.magedu.com
  ErrorLog logs/ssl_error_log
  TransferLog logs/ssl_access_log 定义SSL会话的日志
  LogLevel warn
  SSLEngine on是否启用SSL
  SSLProtocol all -SSLv2 SSL协议的版本(默认禁用SSLv2,all –SSLv2表示使用所有的,但不包括SSLv2)
  SLCipherSuiteALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW 加密方式
  SSLCertificateFile/etc/pki/tls/certs/localhost.crt 证书文件
  SSLCertificateKeyFile/etc/pki/tls/private/localhost.key 私钥文件
  现在先建立CA
  Cd /etc/pki/CA
  Vim ../tls/openssl.cnf
  修改内容
  dir             = /etc/pki/CA
  [ req_distinguished_name ]
  countryName                     = Country Name (2 lettercode)
  countryName_default              = CN
  countryName_min                 = 2
  countryName_max                 = 2
  stateOrProvinceName              = State or Province Name (full name)
  stateOrProvinceName_default       =Henan
  localityName                    = Locality Name (eg, city)
  localityName_default              =ZhengZhou
  0.organizationName              = Organization Name (eg, company)
  0.organizationName_default        = magedu.com
  # we can do this but it is not needednormally :-)
  #1.organizationName             = Second Organization Name (eg,company)
  #1.organizationName_default      = World Wide Web Pty Ltd
  organizationalUnitName          = Organizational Unit Name (eg, section)
  organizationalUnitName_default   = Tech
  commonName                      = Common Name (eg, yourname or your server\'s hostname)
  commonName_max                  = 64
  emailAddress                    = Email Address
  emailAddress_max                = 64
  emailAddress_default            = admin@magedu.com
  生成CA的私钥
  [root@yangyue2 CA]# (umask 077; opensslgenrsa 1024 > private/cakey.pem)
  Generating RSA private key, 1024 bit longmodulus
  ................................................++++++
  .++++++
  e is 65537 (0x10001)
  [root@yangyue2 CA]# ll private/
  总用量 4
  -rw-------. 1 root root 887 4月 19 08:01 cakey.pem
  生成自签证书
  [root@yangyue2 CA]# openssl req -new -x509-key private/cakey.pem -out cacert.pem
  You are about to be asked to enterinformation that will be incorporated
  into your certificate request.
  What you are about to enter is what iscalled a Distinguished Name or a DN.
  There are quite a few fields but you canleave some blank
  For some fields there will be a defaultvalue,
If you enter'.', the field will be left blank.
  Country Name (2 letter code) [CN]:
  State or Province Name (full name) [Henan]:
  Locality Name (eg, city) [ZhengZhou]:
  Organization Name (eg, company)[magedu.com]:
  Organizational Unit Name (eg, section)[Tech]:
  Common Name (eg, your name or your server'shostname) []:ca.magedu.com
  Email Address [admin@magedu.com]:
  创建几个目录
  [root@yangyue2 CA]# mkdir newcerts certscrl
  [root@yangyue2CA]# touch index.txt
  [root@yangyue2 CA]# echo 01 > serial
  [root@yangyue2 CA]# echo 01 > crlnumber
  为HTTP服务发证书:
  [root@yangyue2 CA]# cd /etc/httpd/conf
  [root@yangyue2 conf]# mkdir ssl
  [root@yangyue2 conf]# cd ssl
  [root@yangyue2 ssl]# (umask 077; opensslgenrsa 1024 > httpd.key)
  Generating RSA private key, 1024 bit longmodulus
  ...........................++++++
  .......++++++
  e is 65537 (0x10001)
  证书签署请求
  [root@yangyue2 ssl]# openssl req -new -key httpd.key-out httpd.csr
  You are about to be asked to enterinformation that will be incorporated
  into your certificate request.
  What you are about to enter is what iscalled a Distinguished Name or a DN.
  There are quite a few fields but you canleave some blank
  For some fields there will be a defaultvalue,
  If you enter '.', the field will be leftblank.
  -----
  Country Name (2 letter code) [CN]:
  State or Province Name (full name) [Henan]:
  Locality Name (eg, city) [ZhengZhou]:
  Organization Name (eg, company)[magedu.com]:
  Organizational Unit Name (eg, section)[Tech]:
  Common Name (eg, your name or your server'shostname) []:www.magedu.com
  Email Address [admin@magedu.com]:
  Please enter the following 'extra'attributes
  to be sent with your certificate request
  A challenge password []:
  An optional company name []:
  签署证书:
  [root@yangyue2 ssl]# openssl ca -inhttpd.csr -out httpd.crt
  Using configuration from/etc/pki/tls/openssl.cnf
  Check that the request matches thesignature
  Signature ok
  Certificate Details:
  Serial Number: 1 (0x1)
  Validity
  Not Before: Apr 19 00:11:46 2014 GMT
  Not After : Apr 19 00:11:46 2015 GMT
  Subject:
  countryName               = CN
  stateOrProvinceName       = Henan
  organizationName          = magedu.com
  organizationalUnitName    = Tech
  commonName                =www.magedu.com
  emailAddress              =admin@magedu.com
  X509v3 extensions:
  X509v3 Basic Constraints:
  CA:FALSE
  Netscape Comment:
  OpenSSL Generated Certificate
  X509v3 Subject Key Identifier:
  CA:8B:7D:A1:67:2D:E7:A8:8B:A4:D7:AD:FE:11:9D:F2:AF:48:C1:05
  X509v3 Authority Key Identifier:
  keyid:CF:6B:CE:CB:9F:F4:67:84:24:79:DF:2D:04:5A:7F:59:20:AE:CF:6C
  Certificate is to be certified until Apr 1900:11:46 2015 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
  修改配置文件:
  Vim /etc/httpd/conf.d/ssl.conf
  SSLCertificateFile/etc/httpd/conf/ssl/httpd.crt
  SSLCertificateKeyFile/etc/httpd/conf/ssl/httpd.key
  开启服务:
  Service httpd restart
  将证书复制在本地机器上
  /etc/pki/CA/cacert.pem
  将其名称改为cacert.crt
  导入到浏览器中,这时在浏览器中输入Https://www.magedu.com就可以进行访问了。
  






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-638257-1-1.html 上篇帖子: apache2 php mysql installed by script 下篇帖子: 关于 Apache 的 25 个初中级面试题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表