https----------如何在phpstudy环境下配置apache的https访问以及访问http自动跳转成https

时间:2023-12-11 11:35:14

1、首先在 httpd.conf里面修改几个地方

  找到 #LoadModule ssl_module modules/mod_ssl.so 去掉前面的#

  Include conf/vhosts.conf  在这一行下面增加一行 Include conf/vhosts_ssl.conf 然后去conf文件夹里面创建vhosts_ssl.conf

2、在vhosts_ssl.conf里面写入

  Listen 443
  SSLStrictSNIVHostCheck off
  SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL
  SSLProtocol all -SSLv2 -SSLv3
  <VirtualHost *:443>
      DocumentRoot "D:\phpStudy\zhifu"
      ServerName www.ceshi.com
      ServerAlias ceshi.com
      <Directory "D:\phpStudy\zhifu">
          Options FollowSymLinks ExecCGI
          AllowOverride All
          Order allow,deny
          Allow from all
          Require all granted
      </Directory>
      SSLEngine on
      SSLCertificateFile "D:\phpStudy\Apache\conf\zheng\2_www.ceshi.com.crt"
      SSLCertificateKeyFile "D:\phpStudy\Apache\conf\zheng\3_www.ceshi.com.key"
      SSLCertificateChainFile "D:\phpStudy\Apache\conf\zheng\1_root_bundle.crt"
  </VirtualHost>

3、将证书上传到,上面配置写的对应的路径里面

4、在vhosts.conf里面配置自动跳转

  <VirtualHost *:80>
      DocumentRoot "D:\phpStudy\zhifu"
      ServerName www.ceshi.com
      ServerAlias ceshi.com
         RewriteEngine On
         RewriteRule (.*) https://%{SERVER_NAME}$1 [R]
      <Directory "D:\phpStudy\zhifu">
         Options FollowSymLinks ExecCGI
         AllowOverride All
         Order allow,deny
         Allow from all
         Require all granted
      </Directory>
  </VirtualHost>

5、以上要注意,我写的ceshi的地方,都要改成自己的