您的位置:首页 > 理论基础 > 计算机网络

apache 配置安装ssl证书实现https安全访问全过程

2018-02-08 09:19 766 查看
apache 配置安装ssl证书实现https安全访问全过程

安装证书(贴上未来智库站配置ssl的代码内容),官方的配置复杂且不具有通用性。

1.#修改httpd.conf文件

LoadModule ssl_module modules/mod_ssl.soInclude conf/extra/httpd-ssl.conf#去掉上面两行前的"#"
2.打开extra目录下的httpd-ahssl.conf文件将下载的证书四个文件放置在conf下的ssl目录。httpd-ahssl.conf添加如下代码Listen 443 https
<VirtualHost _default_:443>
  SSLEngine on
  ServerName www.7428.cn:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/214329625123456.pem"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/214329625123456.key"
php_admin_value open_basedir "${SRVROOT}/htdocs/www7428cn;C:/windows/TEMP"
  DocumentRoot "${SRVROOT}/htdocs/www7428cn"
  ErrorDocument 404 "/404/"
# DocumentRoot access handled globally in httpd.conf
# CustomLog "${SRVROOT}/logs/ssl_request.log" \
#          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs/7428cnwww">
# Options Indexes Includes FollowSymLinks
Options Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
    Require all granted
</Directory>
</virtualhost>
<VirtualHost _default_:443>
  SSLEngine on
  ServerName 7428.cn:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/214329625123456.pem"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/214329625123456.key"
 <IfModule rewrite_module>
    RewriteEngine On
    RewriteCond %{http_host} ^7428.cn [NC]
    RewriteRule ^(.*)$ https://www.7428.cn/$1 [L,R=301]
    </IfModule>
php_admin_value open_basedir "${SRVROOT}/htdocs/www7428cn;C:/windows/TEMP"
  DocumentRoot "${SRVROOT}/htdocs/www7428cn"
  ErrorDocument 404 "/404/"
# DocumentRoot access handled globally in httpd.conf
# CustomLog "${SRVROOT}/logs/ssl_request.log" \
#          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "${SRVROOT}/htdocs/www7428cn">
# Options Indexes Includes FollowSymLinks
Options Includes FollowSymLinks
AllowOverride AuthConfig Limit FileInfo
    Require all granted
</Directory>
</virtualhost>
保存后重启apache其中的php_admin_value open_basedir两行代码作用是防止同一个服务器下其他域名站跨站访问。安全至上。ErrorDocument 是配置找不到页面的时候跳转的404页面信息。
<IfModule rewrite_module>里面的内容是实现https://7428.cn重定向到https://www.7428.cn,即不带www的跳转到
带www的下。

官方文件说明:1. 证书文件214329625123456.pem,包含两段内容,请不要删除任何一段内容。2. 如果是证书系统创建的CSR,还包含:证书私钥文件214329625123456.key、证书公钥文件public.pem、证书链文件chain.pem。( 1 ) 在Apache的安装目录下创建cert目录,并且将下载的全部文件拷贝到cert目录中。如果申请证书时是自己创建的CSR文件,请将对应的私钥文件放到cert目录下并且命名为214329625123456.key;( 2 ) 打开 apache 安装目录下 conf 目录中的 httpd.conf 文件,找到以下内容并去掉“#”:
#LoadModule ssl_module modules/mod_ssl.so (如果找不到请确认是否编译过 openssl 插件)
#Include conf/extra/httpd-ssl.conf
( 3 ) 打开 apache 安装目录下 conf/extra/httpd-ssl.conf 文件 (也可能是conf.d/ssl.conf,与操作系统及安装方式有关), 在配置文件中查找以下配置语句:
# 添加 SSL 协议支持协议,去掉不安全的协议
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件如下
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
# 证书公钥配置
SSLCertificateFile cert/public.pem
# 证书私钥配置
SSLCertificateKeyFile cert/214486743260863.key
# 证书链配置,如果该属性开头有 '#'字符,请删除掉
SSLCertificateChainFile cert/chain.pem
( 4 ) 重启 Apache。来源:未来智库 https://www.7428.cn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache技巧