云服务器(uCloud)部署java web项目(八) apache Http重定向到Https

步骤如下: 前提是:1. apache服务器配置了SSL,并能实现HTTPS。就是能访问到443端口。(没有的话,可以参考我以前的文章)

                                2. apache服务器配置正确,能访问到服务器默认端口80。(没有的话,可以参考我以前的文章)

        好了,做好了前期准备后,我们可以来配置apache服务器了。

    (1)sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load  (启动 rewrite mod)

    (2)vi  /etc/apache2/sites-available/000-default.conf  (编辑80端口配置文件)

    (3)在 <\VirtualHost *:80><\VirtualHost> 标签内随便一个地方加入以下三行

           RewriteEngine on

    RewriteCond %{HTTPS} !=on

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]

  (4)sudo apache2ctl configtest    (测试,如果显示ok的话,可以重启服务器) 

    (5)sudo /etc/init.d./apache2 reload

             sudo /etc/init.d/apache2 restard

    (6)浏览器输入 http://localhost:80   (如果显示https://localhost 表示配置正确!)

posted on 2017-07-21 10:23  suosui  阅读(231)  评论(0编辑  收藏  举报

导航