1.windows安装linux
查看ssl模块使用哪个配置文件apache
配置https虚拟主机windows
2.linux安装(暂无)浏览器
因为Apache HTTP Server官方不提供二进制(可执行)的发行版,因此咱们选择贡献者编译完成的版本,此处使用ApacheHaus提供的版本。服务器
打开->Apache Haus Downloads数据结构
下载Apache,其余按需下载dom
此处鄙人选择2.4.x vc9 x86版,下载后以下: ide
Define SRVROOT "/Apache24" #定义配置变量SRVROOT ServerRoot "${SRVROOT}" #服务器根目录 Listen 80 #监听80端口 DocumentRoot "${SRVROOT}/htdocs" #定义文件根目录 htdocs <Directory "${SRVROOT}/htdocs">... #文件根目录htdocs配置 #SSL配置 <IfModule ssl_module> #Include conf/extra/httpd-ssl.conf Include conf/extra/httpd-ahssl.conf SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule>
出现此页面则说明apache服务器已正常运行测试
从Apache Haus下载的apache服务器通常配置默认开启ssl。此处做配置详解:
因为apache已经自带ssl模块,省去了下载的事。
LoadModule ssl_module modules/mod_ssl.so
*科普:httpd-ssl.conf 与httpd-ahssl.conf有什么不一样? 根据命名能够看出 ahssl 是 Apache Haus 自带的ssl配置,其已经为咱们生成好ssl私钥和证书文件,于conf/ssl目录下。 固然你能够不使用ahssl配置,而是修改使用ssl配置虚拟主机,本身去生成ssl服务器证书。
虚拟主机配置区别
Https协议使用443端口,使用httpd-ssl.conf或httpd-ahssl.conf配置虚拟主机
Http协议使用80端口,使用httpd-vhosts.conf配置虚拟主机
若是虚拟主机在2个端口均有配置,则使用https访问时,使用httpd-ssl.conf或httpd-ahssl.conf配置;使用http访问时,使用httpd-vhosts.conf配置
复制httpd-ahssl.conf 内的虚拟主机配置,修改以下:
<VirtualHost _default_:443> #监听443端口的虚拟主机, _default_ 是默认根目录,通常指访问localhost,此处修改成虚拟主机名(以下的baiduu.com) SSLEngine on ServerName baiduu.com:443 #修改此处虚拟主机名 SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt" #ssl证书文件 SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key" #ssl私钥文件 DocumentRoot "D:/workplace/baiduu" #修改此处虚拟主机目录 # 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"> Options Indexes Includes FollowSymLinks AllowOverride AuthConfig Limit FileInfo Require all granted </Directory> </virtualhost>
重启apache,使用https://www.baiduu.com 访问试试。
固然,若是你在httpd-vhosts.conf中也配置了此虚拟主机。则能够输入http://www.baiduu.com 使用80端口访问此页面。
1.在DOS命令下进入apache/bin目录
2.执行命令
set OPENSSL_CONF=..\conf\openssl.cnf
请在执行以前确保conf\openssl.cnf 存在,不然会出现:WARNING: can't open config file: /usr/local/ssl/openssl.cnf 信息提示。
3.生成私钥文件:
执行命令
openssl genrsa 1024>server.key
说明:这是用128位rsa算法生成密钥,获得server.key文件。 > 是输出文件的标识符
这种生成方法生成的是没有密钥的私钥文件。固然,Apache提供了加入密钥(Password)的命令,就是加入参数-des3。命令为:
openssl genrsa 1024 -des3 > server.key
使用上述命令生成私钥文件是须要输入密钥的,运行的时候会让你输入并确认你的密钥。可是在Windows环境下会致使如下错误:错误:Apache启动失败,错误提示是:Init: SSLPassPhraseDialog builtin is not supported on Win32 (key file .....)
缘由是window下的apache不支持加密的私钥文件。
注:生成的证书中RSA密钥对的默认长度是1024,取值是2的整数次方。建议使用4096以上。
4.生成证书请求文件。
执行命令
openssl req -new -key server.key > server.csr
说明:这是用步骤3的密钥生成证书请求文件server.csr, 这一步会有不少参数,须要一一输入。
按提示输入一系列的参数:
Country Name (2 letter code) [AU]:CN ISO国家代码(只支持两位字符)
State or Province Name (full name) [Some-State]:ZJ所在省份
Locality Name (eg, city) []:HZ所在城市
Organization Name (eg, company):SW_TECH公司名称
Organizational Unit Name (eg, section) []:SW_TECH组织名称
Common Name (eg, YOUR name) []:kedou.com申请证书的域名
Email Address []:admin@admin.com 管理员邮箱
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: 交换密钥
An optional company name []: 注:Common Name必须和httpd.conf中server name必须一致,不然apache不能启动 (启动apache时错误提示为:RSA server certificate CommonName (CN) `Kedou' does NOT match server name!? )
5.签署服务器证书文件:
执行命令行
openssl req -x509 -days 365 -key server.key -in server.csr > server.crt
说明:这是用步骤3,4的的密钥和证书请求生成证书server.crt,-days参数指明证书有效期,单位为天,x509表示生成的为X.509证书。
以上签署证书仅仅作测试用,真正运行的时候,应该将CSR发送到一个CA返回真正的证书。网上有些文档描述生成证书文件的过程比较繁琐,就是由于 他们本身创建了一个CA中心,而后再签署server.csr
用openssl x509 -noout -text -in server.crt 能够查看证书的内容。证书实际上包含了Public Key
1.在DOS命令下进入apache/bin目录
2.签发证书
openssl req -config ../conf/openssl.cnf -new -out server.csr -keyout server.pem
其中openssl.cnf为apache自带的openssl配置文件,引用到该文件的完整路径
输入两次密码,随便什么密码,而后一直回车,跳过下面的输入
3.生成密钥文件
openssl rsa -in server.pem -out server.key
输入刚才制定的密码
4.生成证书文件
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 365
6.把 server.key,server.crt 复制到conf/虚拟主机名/ssl/目录下
7.配置https虚拟主机
打开httpd-ssl.conf,复制httpd-ahssl.conf的虚拟主机配置(固然你能够直接在httpd-ahssl.conf配置使用),更改以下:
<VirtualHost 虚拟主机名:443> SSLEngine on ServerName 虚拟主机名:443 SSLCertificateFile "${SRVROOT}/conf/虚拟主机名/ssl/server.crt" #ssl证书文件 SSLCertificateKeyFile "${SRVROOT}/conf/虚拟主机名/ssl/server.key" #ssl私钥文件 DocumentRoot "虚拟主机目录" #修改此处虚拟主机目录 # 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"> Options Indexes Includes FollowSymLinks AllowOverride AuthConfig Limit FileInfo Require all granted </Directory> </virtualhost>
重启apache,使用https://www.baiduu.com 访问试试。
固然,若是你在httpd-vhosts.conf中也配置了此虚拟主机。则能够输入http://www.baiduu.com 使用80端口访问此页面。