https配置(阿里云win+phpstudy2016)

一 下載證書

我這里的下載流程只供參考,詳細的步驟可以去百度搜索。最終的目的是得到4個證書文件

  1. 首先申請阿里云免費的ssl認證證書,認證證書申請過程比較簡單。請自行百度。登陸阿里云之后,在安全(云盾)板塊下-CA證書服務
購買
  1. 申請過程比較簡單,需要等待阿里云審核通過。通過之后會顯示證書。點擊“下載”(此教程主要是針對Apache);
下載
  1. 這里選取apache證書。下載的文件包里面有四個文件:

【123.key證書私鑰文件,123.pem,證書公鑰文件chain.pem,證書鏈文件 public.pem 】

二 配置phpStudy的Apache

  1. 開啟apache的編譯ssl模塊,如圖打開phpstudy—其它選項設置—PHP擴展及設置—php擴展—php-openssl前面打勾
配置
  1. 打開httpd.conf文件(C:\phpStudy\Apache\conf\httpd.conf根據這個規律去找你安裝的位置)
  2. 更改httpd.conf的相應文件
  • 找到LoadModule ssl_module modules/mod_ssl.so (如果前面有#號把#號去調打開此擴展)
  • 找到Include conf/vhosts.conf(如果前面有#號把#號去了)
  • 找到Include conf/extra/httpd-ssl.conf(如果前面有#號把#號去了,如果沒有此段文字,就搜索# Secure (SSL/TLS) connections,并在它的下一行寫上)
#Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
  • 現在重啟Apache 肯定是紅燈,如果把Include conf/extra/httpd-ssl.conf前面加#注釋以后能正常啟動說明引入文件成功

  • 打開httpd-ssl.conf(C:\phpStudy\Apache\conf\extra根據這個規律去找你安裝的位置)

  • 把下面<VirtualHost><VirtualHost>的內容全部刪除

    <VirtualHost >
        。。。。。。
    </VirtualHost>    
    
    • 更改如下

      <VirtualHost *:443>
          SSLEngine on
          SSLProtocol TLSv1 TLSv1.1 TLSv1.2
          SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
          SSLCertificateFile "C:/phpStudy/Apache/cert/public.pem"
          SSLCertificateKeyFile  "C:/phpStudy/Apache/cert/11.key"
          SSLCertificateChainFile  "C:/phpStudy/Apache/cert/chain.pem"
          ServerName www.exam.com
          DocumentRoot "C:\phpStudy\WWW\exam"
      </VirtualHost>    
      
      • 以上參數說明

        SSLCipherSuite是阿里云提供的,下載證書的頁面有

        SSLCertificateFile SSLCertificateKeyFile SSLCertificateChainFile文件是證書的絕對路徑

        ServerName 是你網站的域名這個域名必須是和購買證書的iP是對應的映射關系

        DocumentRoot 是www. exam.com域名對應的項目地址:單訪問ServerName時就打開WWW下的exam文件(我用的tp框架且把入口index.php放在了項目的根目錄下,及直接運行exam/index.php文件了)

        • 再次重啟apache正常啟動 如果還是紅燈肯定是哪里寫錯了,一定保證httpd.cpmf的Include conf/extra/httpd-ssl.conf開啟

        http-ssl.conf源碼

        #
        # This is the Apache server configuration file providing SSL support.
        # It contains the configuration directives to instruct the server how to
        # serve pages over an https connection. For detailed information about these 
        # directives see <URL:http://httpd.apache.org/docs/trunk/mod/mod_ssl.html>
        # 
        # Do NOT simply read the instructions in here without understanding
        # what they do.  They're here only as hints or reminders.  If you are unsure
        # consult the online docs. You have been warned.  
        #
        
        #
        # Pseudo Random Number Generator (PRNG):
        # Configure one or more sources to seed the PRNG of the SSL library.
        # The seed data should be of good random quality.
        # WARNING! On some platforms /dev/random blocks if not enough entropy
        # is available. This means you then cannot use the /dev/random device
        # because it would lead to very long connection times (as long as
        # it requires to make more entropy available). But usually those
        # platforms additionally provide a /dev/urandom device which doesn't
        # block. So, if available, use this one instead. Read the mod_ssl User
        # Manual for more details.
        #
        #SSLRandomSeed startup file:/dev/random  512
        #SSLRandomSeed startup file:/dev/urandom 512
        #SSLRandomSeed connect file:/dev/random  512
        #SSLRandomSeed connect file:/dev/urandom 512
        
        #
        # When we also provide SSL we have to listen to the 
        # standard HTTP port (see above) and to the HTTPS port
        #
        # Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
        #       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
        #
        Listen 443
        
        ##
        ##  SSL Global Context
        ##
        ##  All SSL configuration in this context applies both to
        ##  the main server and all SSL-enabled virtual hosts.
        ##
        
        #   Pass Phrase Dialog:
        #   Configure the pass phrase gathering process.
        #   The filtering dialog program (`builtin' is a internal
        #   terminal dialog) has to provide the pass phrase on stdout.
        SSLPassPhraseDialog  builtin
        
        #   Inter-Process Session Cache:
        #   Configure the SSL Session Cache: First the mechanism 
        #   to use and second the expiring timeout (in seconds).
        #SSLSessionCache         "dbm:/Apache24/logs/ssl_scache"
        SSLSessionCache        "shmcb:/Apache24/logs/ssl_scache(512000)"
        SSLSessionCacheTimeout  300
        
        ##
        ## SSL Virtual Host Context
        ##
        
        <VirtualHost *:443>
            SSLEngine on
            SSLProtocol TLSv1 TLSv1.1 TLSv1.2
            SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
            SSLCertificateFile "C:/phpStudy/Apache/cert/public.pem"
            SSLCertificateKeyFile  "C:/phpStudy/Apache/cert/1.key"
            SSLCertificateChainFile  "C:/phpStudy/Apache/cert/chain.pem"
            ServerName www.exam.com
            DocumentRoot "C:\phpStudy\WWW\exam"
        </VirtualHost>        
        

        三 自動轉htpps

        在項目的根目錄下找到并打開.htaccess(C:\phpStudy\WWW\項目名稱.htaccess如果沒有自建)

        內容如下隱藏了index.php和強行自動跳轉https的配置

        <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php
        </IfModule>
        

?

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,431評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,637評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,555評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,900評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,629評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,976評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,976評論 3 448
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,139評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,686評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,411評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,641評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,129評論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,820評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,233評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,567評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,362評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,604評論 2 380

推薦閱讀更多精彩內容