Apache配置https证书并跳转

对于网站实现https安全访问,需要做到以下几步:
1、在域名解析商处申请ssl证书,该证书可以免费申请,申请下来后包括很多web配置的证书类型
如下图:
Apache配置https证书并跳转
2、搭建web服务,我这里搭建的环境是LAMP环境。
3、将ssl证书上传至对应的目录。
4、配置ssl证书的认证访问。
5、配置httpd的host访问。
具体配置如下:
域名的解析方式,在这里就不做赘述了。
1、 关于lamp的环境搭建我这里使用的yum安装的环境,系统为centos6.9
关于环境的搭建这里不进行介绍。
LAMP环境安装完成后,确认是否有默认安装安装Apache的mod_ssl
模块。如果没有安装使用yum install mod_ssl -y进行安装。该模块安装完成后,会在/etc/httpd/conf.d生成ssl.conf文件。
Apache配置https证书并跳转
2、证书上传至:/etc/ssl/Apache下。
Apache配置https证书并跳转
3、配置ssl证书认证,将ssl.conf配置文件进行备份,并重新命名(根据自己的域名进行命令)。
Apache配置https证书并跳转
并进行重新配置。
Apache配置https证书并跳转
可以将一下内容粘贴复制在自己的ssl配置文件中。

LoadModule ssl_module modules/mod_ssl.so
Listen 443
SSLPassPhraseDialog  builtin
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout  300
SSLMutex default
SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
<VirtualHost _default_:443>
ServerName www.自己域名.wang
DocumentRoot /var/www/html/dede
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
SSLCertificateFile /etc/ssl/Apache/2_自己证书.crt
SSLCertificateKeyFile /etc/ssl/Apache/3_自己证书.key
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
CustomLog logs/ssl_request_log \
</VirtualHost>

4、配置httpd主机host。
Apache配置https证书并跳转
配置文件:

<VirtualHost *:80>
    DocumentRoot /var/www/html/dede
    ServerName www.自己域名.wang
    ErrorLog logs/自己域名.wang-error_log
    CustomLog logs/自己域名.wang-access_log common
#       DirectoryIndex index.php index.html
        <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^自己域名.wang$
    RewriteRule ^/(.*)$ https://www.自己域名.wang/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} ^www.自己域名.wang$
   RewriteRule ^/(.*)$ https://www.自己域名.wang/$1 [L,R=301]
        </IfModule>
</VirtualHost>

实现了http跳转https访问。
Apache配置https证书并跳转
Apache配置https证书并跳转

猜你喜欢

转载自blog.51cto.com/zhanx/2153306
今日推荐