分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

apache2.4配置https

发布时间:2023-09-06 01:30责任编辑:胡小海关键词:apache配置http
1、获取证书
1.1 openssl生成SSL证书(自行百度)
1.2 新浪云,腾讯云,阿里云等等都有提供免费的SSL证书

2、证书安装(以腾讯云提供SSL为例)
编辑Apache根目录下 conf/httpd.conf 文件,
找到 #LoadModule ssl_module modules/mod_ssl.so#Include conf/extra/httpd-ssl.conf,去掉前面的#号注释;
编辑Apache根目录下 conf/extra/httpd-ssl.conf 文件,修改如下内容:
<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>
配置完成后,重新启动 Apache 就可以使用https://www.domain.com来访问了。
注:
配置文件参数
说明
SSLEngine on启用SSL功能
SSLCertificateFile证书文件
SSLCertificateKeyFile私钥文件
SSLCertificateChainFile

证书链文件










3、apache配置重定向
在.htaccess文件中加入如下代码:
<IfModule mod_rewrite.c>RewriteEngine onRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]</IfModule>
ps:如果项目使用了.htaccess隐藏了index.php(例如tp3.2),可在.htaccess文件中加入如下代码:
<IfModule mod_rewrite.c>
RewriteEngine OnRewriteCond %{HTTPS} offRewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . index.php
</IfModule>
也可以利用php做https的跳转:
<?php if ($_SERVER["HTTPS"] <> "on") ???{ ???$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; ???header("Location: ".$xredir); ???}?>
然后伪静态就正常写去掉index.php的功能:
<IfModule mod_rewrite.c>RewriteEngine onRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]</IfModule>
配置完成后,http就可以重定向到https了。


4、遇到到问题
4.1 外网443端口被防火墙关闭。
4.2 在windows Server 2012服务器上配置httpd-ssl.conf时VirtualHost *:443 * 号使用域名出错,这里建议用*/ip

apache2.4配置https

原文地址:http://www.cnblogs.com/jie-hu/p/8034226.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved