phpstudy(apache) 配置 https协议

域名已经备案的前提下

1、在腾讯月云上申请ssl证书(对于个人可以用免费版

2、下载证书,增加一条域名解析,采用txt解析方式

3、将证书上传到服务器端,比如apache的conf文件夹下,新建一个cert文件夹,将下载的证书中三个都保存到cert文件夹下

4、开启ssl扩展,并在conf下的httpd.conf文件中将#LoadModule ssl_module modules/mod_ssl.so和#Include conf/extra/httpd-ssl.conf这两项的#去掉

如果此时:#Include conf/extra/httpd-ssl.conf中的#去掉之后apache报错无法启动,此时的错误是conf/extra/httpd-ssl.conf文件有错误可以将此文件所有内容删除

5、在conf/extra/httpd-ssl.conf文件中中下面内容替换

Listen 443
<VirtualHost *:443>
  SSLEngine on
  SSLProtocol all -SSLv2 -SSLv3
  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
  SSLCertificateFile "D:/phpStudy/Apache/conf/cert/2_www.yourmain.com.crt"
  SSLCertificateKeyFile "D:/phpStudy/Apache/conf/cert/3_www.yourmain.com.key"
  SSLCertificateChainFile "D:/phpStudy/Apache/conf/cert/1_root_bundle.crt"
  DocumentRoot  "D:\phpStudy\WWW\test"
  <Directory />
    Options +Indexes +FollowSymLinks +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>  

6、重启服务器,https成功配置

最后:从http跳转到https

修改apache

7、修改conf/httpd.conf中:

LoadModule rewrite_module modules/mod_rewrite.so  前面#去掉

AllowOverride None 修改为 AllowOverride All

8、在项目入口目录下添加.htaccess

并加入

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
</IfModule>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值