Home  >  Article  >  Backend Development  >  How does phpstudy's Apache configuration convert HTTP to HTTPS access?

How does phpstudy's Apache configuration convert HTTP to HTTPS access?

青灯夜游
青灯夜游forward
2018-10-22 17:28:504348browse

本篇文章给大家带来的内容是介绍phpstudy的Apache配置SSL成功将HTTP转换为HTTPS访问。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。

1、去阿里云购买证书 有免费一年的证书 最多20个 一个证书需要填写一个二级域名 www.xxx.com
开启apache相应配置

#修改httpd.conf文件
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
LoadModule rewrite_module
#去掉上面三行前的"#"

保存退出

在apache目录下的conf目录下新建一个cert目录,将你的证书文件放在这里面

开启php的openssl模块,在phpstudy的“php扩展及设置”里面开启即可

修改httpd-ssl.conf文件,保存退出
在…\Apache\conf\extra目录下,打开httpd-ssl.conf文件(注:先备份一遍,以免出错,因为这个文件的错误我重装phpstuy不下10回)
在文件里定位到  Listen 443  这句话这里,把  从这句话到这个文件结尾的文本    全部注释掉或者删除掉,替换成以下代码

Listen 443   //这里强调一下,如果Listen 443这句代码在这个文件里重复出现了,即重复监听,apache会报错,然后不能启动
SSLStrictSNIVHostCheck off
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL
SSLProtocol all -SSLv2 -SSLv3
#这里的路径设置你的网站根目录
DocumentRoot "C:\phpStudy\PHPTutorial\WWW"  
#这里xxxxx.com替换成你的域名
ServerName www.xxxxx.com    
#这里xxxxx.com替换成你的域名
ServerAlias xxxxx.com          
#这里的路径设置你的网站根目录    
      
    Options FollowSymLinks ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted

SSLEngine on
#你的公钥文件
SSLCertificateFile "C:/phpStudy/PHPTutorial/Apache/conf/cert/server.crt"

#你的私钥文件(有的机构命名为private或者以你的域名为文件名命名)
SSLCertificateKeyFile “C:/phpStudy/PHPTutorial/Apache/conf/cert/server.key”
#证书链文件(有的机构命名为CA) 我尝试过注释掉这个选项,结果apache不能运行
SSLCertificateChainFile “C:/phpStudy/PHPTutorial/Apache/conf/cert/chain.crt”
重启apache,看看能不能正常启动,如果有异常,尝试把第4步中httpd-ssl.conf代码恢复注释(把#重新加上去,保存退出),再次重启apache,如果此时能够正常启动,则说明httpd-ssl.conf文件中有错误(是不是重复监听了?证书路径对不对?证书是否有效?),请认真检查,直到能够正常启动apache

项目http访问自动跳转https配置根目录 .htaccess

  	Options -MultiViews
 
    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

The above is the detailed content of How does phpstudy's Apache configuration convert HTTP to HTTPS access?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete