Apache配置HTTPS功能

來源:互聯網
上載者:User

標籤:htttps aapche

apache配置https一、yum 安裝openssl和openssl-devel,httpd-devel二、產生認證(也可以從公司的憑證授權單位擷取):
#建立伺服器密鑰  openssl genrsa -des3 1024  > /usr/local/apache/conf/server.key   # 從密鑰中刪除密碼(以避免系統啟動後被詢問口令) openssl rsa -in /usr/local/apache/conf/server.key > /usr/local/apache/conf/server2.keymv /usr/local/apache/conf/server2.key  /usr/local/apache/conf/server.key#建立伺服器密鑰請求檔案openssl req -new -key /usr/local/apache/conf/server.key -out /usr/local/apache/conf/server.csr5>openssl x509 -in /usr/local/apache/conf/server.csr -out# 建立伺服器憑證  /usr/local/apache/conf/server.crt -req -signkey /usr/local/apache/conf/server.key -days 365
三、修改Apache的設定檔httpd.conf

開啟ssl模組,沒有這個模組就需要安裝依賴包:mod_ssl,安裝後就會在modules裡面找到:

LoadModule ssl_module         modules/mod_ssl.so

引入ssl設定檔,增加支援ssl:

Include conf/extra/httpd-ssl.conf(去掉行首的注釋)
  • 啟動重新導向(可選),使用使用者HTTP訪問自動重新導向為HTTPS,直接在http.conf最後配置即可,在httpd.conf檔案尾加入如下內容:

    RewriteEngine onRewriteCond %{SERVER_PORT} !^443$RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
四、修改加密檔案ssl.conf,通過yum安裝好的httpd,在conf.d目錄下面有ssl.conf設定檔,我們需要在裡面配置一個VirtualHost和配置認證和密鑰:
LoadModule ssl_module modules/mod_ssl.soListen 443SSLPassPhraseDialog  builtinSSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)SSLSessionCacheTimeout  300SSLMutex defaultSSLRandomSeed startup file:/dev/urandom  256SSLRandomSeed connect builtinSSLCryptoDevice builtinSSLProtocol all -SSLv2 -SSLv3SSLHonorCipherOrder onSSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:<VirtualHost _default_:443>     # 必須有一個虛擬機器主機,這樣才可以使用跳轉功能和使用443連接埠訪問DocumentRoot "/home/store/webroot"Servername https://xxx.com/ErrorLog logs/ssl_error_logTransferLog logs/ssl_access_logLogLevel warnSSLEngine onSSLCertificateFile /etc/httpd/conf/cert/xxx.com.crtSSLCertificateKeyFile /etc/httpd/conf/cert/xxx.com.key</VirtualHost>
五、重啟Apache

service httpd restart

  1. 在瀏覽器輸入https://網域名稱 或者 網域名稱:443,如果兩個能正常訪問,表示https已經配置成功。

  2. 在瀏覽器輸入 網域名稱,如果能夠正常跳轉到https串連上,那說明跳轉功能正常。

  • 啟動apache 碰到下面問題:

    Invalid command ‘SSLPassPhraseDialog‘, perhaps misspelled or defined by a module not included in the server configuration

    到apache的bin 目錄下面執行 ./httpd -l 看看有沒有mode_ssl.c,這個錯誤說明ssl模組安裝沒有成功。
    解決辦法:

  • 1、重新編譯apache,加上--enable-ssl --with-ssl參數

  • 2、把ssl模組加入到已經編譯好的apache中
    首先,使用 whereis openssl 命令擷取lib和include的路徑

[[email protected] /usr/local/apache/modules]# whereis opensslopenssl: /usr/bin/openssl /usr/lib/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz

然後 在apache 源碼的modules/ssl檔案夾下,使用命令/usr/sbin/apxs -i -a -D HAVE_OPENSSL=1 -I/usr/include/openssl/ -L/usr/lib/openssl/ -c *.c -lcrypto -lssl -ldl(apxs需要安裝http-devel才有,雖然如此,我還是沒有編譯成功,於是就在其他已經編譯了這個模組的機器上拷貝mod_ssl.so到apache模組目錄/usr/local/apache/modules)


本文出自 “夢想照進現實” 部落格,請務必保留此出處http://lookingdream.blog.51cto.com/5177800/1919718

Apache配置HTTPS功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.