Windows 下配置 Apache 支持 https
1、首页进入apache bin目录 2、新建系统环境变量 OPENSSL_CONF => E:\Apache\conf\openssl.cnf 3、openssl genrsa 1024 >server.key 4、openssl req -new -config openssl.cnf -key server.key >server.csr 5、openssl req -x509 -days 3650 -key server.key -in server.csr >server.crt
6、配置Apahce !!! 核心步骤 !!!
6.1 在http.conf文件中去掉下面代码前的#号
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule ssl_module modules/mod_ssl.so #Include conf/extra/httpd-ssl.conf
6.2 修改 F:/Apache/conf/extra/httpd-ssl.conf 文件
<VirtualHost _default_:443> DocumentRoot "F:/Apache/htdocs/ushark.net" ServerName www.ushark.net:443 SSLCertificateFile "F:/Apache/bin/server.crt" SSLCertificateKeyFile "F:/Apache/bin/server.key" </VirtualHost>
7、配置http自动跳转到https,在 httpd-vhosts.conf 文件中编辑如下内容,也可参考这篇文章:https://wiki.apache.org/httpd/RedirectSSL
<VirtualHost *:80>
DocumentRoot "F:/Apache/htdocs/ushark.net"
ServerName www.ushark.net
Redirect / https://www.ushark.net/ # !!! 核心代码 !!!
</VirtualHost>
8、httpd -k restart // 重新启动Apache,报错的话就查找相应原因解决