Apache服务器部署SSL安全证书

我使用的apache版本为2.4.39,通过wampserver安装环境

关键文件:

首先找到apache的文件夹地址,我的路径为

D:/wamp64/bin/apache/apache2.4.39

在该目录下去到conf文件中找到两个文件

①httpd-ssl.conf :在conf/extra中

②httpd.conf :就在conf里

步骤:

1.引入httpd-ssl.conf

先打开文件①,搜索 Include conf/extra/httpd-ssl.conf 这条语句,如果是被注释掉的话,解除注释,这一条语句是用来引入文件②的,有关ssl证书的配置都在文件②内部进行

2.配置httpd-ssl.conf

然后来到文件②处:

搜索<VirtualHost _default_:443>,找到<VirtualHost _default_:443>与</VirtualHost >之间的部分,如下

<VirtualHost _default_:443>

#   General setup for the virtual host
DocumentRoot "D:/wamp64/www"
ServerName www.yours.com
ServerAdmin admin@example.com
ErrorLog ""
TransferLog ""

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4

#   Server Certificate:
#   Point SSLCertificateFile at a PEM encoded certificate.  If
#   the certificate is encrypted, then you will be prompted for a
#   pass phrase.  Note that a kill -HUP will prompt again.  Keep
#   in mind that if you have both an RSA and a DSA certificate you
#   can configure both in parallel (to also allow the use of DSA
#   ciphers, etc.)
#   Some ECC cipher suites (http://www.ietf.org/rfc/rfc4492.txt)
#   require an ECC certificate which can also be configured in
#   parallel.
SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.39/conf/cert/gdyjydrd.com_zheng_shu.cer"
#SSLCertificateFile "${SRVROOT}/conf/server-dsa.crt"
#SSLCertificateFile "${SRVROOT}/conf/server-ecc.crt"

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#   ECC keys, when in use, can also be configured in parallel
SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.39/conf/key/gdyjydrd.com.key"
#SSLCertificateKeyFile "${SRVROOT}/conf/server-dsa.key"
#SSLCertificateKeyFile "${SRVROOT}/conf/server-ecc.key"

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convenience.
SSLCertificateChainFile "D:/wamp64/bin/apache/apache2.4.39/conf/cert/gdyjydrd.com_zheng_shu_lian.cer"

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#   Note: Inside SSLCACertificatePath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
#SSLCACertificatePath "${SRVROOT}/conf/ssl.crt"
#SSLCACertificateFile "${SRVROOT}/conf/ssl.crt/ca-bundle.crt"

#   Certificate Revocation Lists (CRL):
#   Set the CA revocation path where to find CA CRLs for client
#   authentication or alternatively one huge file containing all
#   of them (file must be PEM encoded).
#   The CRL checking mode needs to be configured explicitly
#   through SSLCARevocationCheck (defaults to "none" otherwise).
#   Note: Inside SSLCARevocationPath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
#SSLCARevocationPath "${SRVROOT}/conf/ssl.crl"
#SSLCARevocationFile "${SRVROOT}/conf/ssl.crl/ca-bundle.crl"
#SSLCARevocationCheck chain

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   TLS-SRP mutual authentication:
#   Enable TLS-SRP and set the path to the OpenSSL SRP verifier
#   file (containing login information for SRP user accounts). 
#   Requires OpenSSL 1.0.1 or newer. See the mod_ssl FAQ for
#   detailed instructions on creating this file. Example:
#   "openssl srp -srpvfile ${SRVROOT}/conf/passwd.srpv -add username"
#SSLSRPVerifierFile "${SRVROOT}/conf/passwd.srpv"

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context. 
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "${SRVROOT}/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is sent or allowed to be received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly. 
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                          

内容非常多,但是不要怕,跟着改几行就行

很多教程到这一步会说删掉原本VirtualHost内部的代码然后重新复制一遍他们的代码,但是起码在2.4.39版本的apache这一步不能删,只能改,按如下步骤操作:

2.1在SSLCertificateFile处配置安全证书路径,如

SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.39/conf/cert/myWeb.com_zheng_shu.cer"

2.2在SSLCertificateKeyFile处配置私钥文件路径,如:

SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.39/conf/key/myWeb.com.key"

2.3在SSLCertificateChainFile处配置另一个安全证书的路径,如

SSLCertificateChainFile "D:/wamp64/bin/apache/apache2.4.39/conf/cert/myWeb.com_zheng_shu_lian.cer"

2.4在DocumentRoot处配置项目文件夹路径,如

DocumentRoot "D:/wamp64/www"

2.5在ServerName处配置网页路径,后面加上:443,如

ServerName www.myWeb.com:443

2.6在ErrorLog 和 TransferLog处配置对应的.log文件,如果没有就加上,如

ErrorLog "D:/wamp64/bin/apache/apache2.4.39/logs/error.log"

TransferLog "D:/wamp64/bin/apache/apache2.4.39/logs/access.log"

2.7然后查找SSLSessionCache,将后面跟着"shmcb:${SRVROOT}/logs/ssl_scache(512000)"的那一条语句注释掉(这一个操作不知道为什么,根据本地报错日志改掉的)

然后重启apache,不出意外就没有意外会出现了

不出意外出了意外的情况

重启apache,apache服务器启动失败,wamp成黄色,先不要慌张,去打开文件①,注释掉里面的的

Include conf/extra/httpd-ssl.conf 这一条语句后再重启一遍试试,如果apache服务器启动成功,就是文件②有报错,这时候打开apache的报错日志查看即可,在wamp可以这么操作:

鼠标左键点击一下wamp图标,然后按照如图步骤依次点击

打开apache报错日志后可以看到类似语句:

[Mon Nov 20 10:46:25.131837 2023] [mpm_winnt:notice] [pid 4521748:tid 536] AH00456: Apache Lounge VC15 Server built: Mar 28 2019 11:59:33
[Mon Nov 20 10:46:25.131837 2023] [core:notice] [pid 4521748:tid 536] AH00094: Command line: 'D:\\wamp64\\bin\\apache\\apache2.4.39\\bin\\httpd.exe -d D:/wamp64/bin/apache/apache2.4.39'
[Mon Nov 20 10:46:25.132825 2023] [mpm_winnt:notice] [pid 4521748:tid 536] AH00418: Parent: Created child process 4463656
[Mon Nov 20 10:46:25.321288 2023] [ssl:warn] [pid 4463656:tid 468] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
每一条信息的第一个[]内是时间信息,我们注意一下第二个[]内如果出现ssl:warn,就说明这一条是ssl配置文件的报错,解决问题就有头绪了。

发现报错信息如下:

AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]

然后去文件②中搜索SSLSessionCache,注释掉着"SSLSessionCache  shmcb:${SRVROOT}/logs/ssl_scache(512000)"这一条语句后,重启apache,发现重启成功了,安全证书也生效了,完美。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值