1.1 openssl生成SSL证书(自行百度)php
1.2 腾讯云,阿里云,百度云等等都有提供免费的SSL证书html
编辑Apache根目录下 conf/httpd.conf 文件,找到#LoadModule ssl_module/mod_ssl.so 和 #Include conf/extra/httpd-ssl.conf,去掉前面的#号注释;apache
编辑Apache跟目录下 conf/extra/httpd-ssl.conf 文件,修改以下内容:
windows
<VirtualHost *:443> DocumentRoot "/var/www/html" ServerName www.domain.com:443 SSLEngine on SSLCertificateFile /usr/local/apache/conf/2_www.domain.com_cert.crt SSLCertificateKeyFile /usr/local/apache/conf/3_www.domain.com.key SSLCertificateChainFile /usr/local/apache/conf/1_root_bundle.crt </VirtualHost>
ruby
配置完成后,从新启动 Apache 就能够使用https://www.domain.com
来访问了。
注:
配置文件参数 | 说明 |
SSLEngine on | 启用SSL功能 |
SSLCertificateFile | 证书文件 |
SSLCertificateKeyFile | 私钥文件 |
SSLCertificateChainFile | 证书链文件 |
dom在.htaccess文件中加入以下代码:
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] </IfModule>
阿里云
ps:若是项目使用了.htaccess隐藏了index.php(例如tp3.2),可在.htaccess文件中加入如
在.htaccess文件中加入以下代码:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
<IfModule mod_rewrite.c></IfModule>
spa
<?php if ($_SERVER["HTTPS"] <> "on") { $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?>
而后伪静态就正常去掉index.php功能:code
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] </IfModule>
配置完成后,http就能够重定向到https了。
4.1 外网443端口被防火墙关闭
4.2 在windows Server 2012服务器上配置
时VirtualHost *:443 * 号使用域名出错,这里建议用*/iphttpd-ssl.conf