步驟以下: 前提是:1. apache服務器配置了SSL,並能實現HTTPS。就是能訪問到443端口。(沒有的話,能夠參考我之前的文章)apache
2. apache服務器配置正確,能訪問到服務器默認端口80。(沒有的話,能夠參考我之前的文章)瀏覽器
好了,作好了前期準備後,咱們能夠來配置apache服務器了。服務器
(1)s
udo 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端口配置文件)spa
(3)在 <\VirtualHost *:80><\VirtualHost> 標籤內隨便一個地方加入如下三行rest
RewriteEngine on
code
RewriteCond %{HTTPS} !=on
it
RewriteRule
^(.*) https://%{SERVER_NAME}$1 [L,R]
test
(4)sudo apache2ctl configtest (測試,若是顯示ok的話,能夠重啓服務器) 配置
(5)sudo /etc/init.d./apache2 reload
sudo /etc/init.d/apache2 restard
(6)瀏覽器輸入 http://localhost:80 (若是顯示https://localhost 表示配置正確!)