Apache集成版環境phpStudy配置安https安全套接字層SSL
在設置Apache + SSL之前, 需要做:
安裝帶有ssl版本的Apache。並且要確保apache編譯了ssl模塊(開啟方式:打開phpstudy——設置——PHP模塊擴展——php-openssl前面勾選上)
並且ssl需要的文件在如下的位置:
[Apache安裝目錄]/modules/ mod_ssl.so
[Apache安裝目錄]/bin/ openssl.exe, libeay32.dll, ssleay32.dll, openssl.cnf
[Apache安裝目錄]/conf/ openssl.cnf
創建SSL證書(PHPStudy裡面自帶了openssl,但是bin目錄下沒有openssl.cnf,需要將conf下的openssl.cnf拷貝一份到bin目錄下,但總體原理一樣)
步驟一:
執行命令:
openssl genrsa 1024 >tian_server.key
(RSA密鑰對的默認長度是1024,取值是2的整數次方,並且密鑰長度約長,安全性相對會高點)。
完成密鑰server.key生產完畢後進行步驟二操作。
步驟二:
生產為簽署的server.csr
繼續在bin目錄下執行命令:
openssl req -new -config openssl.cnf -key tian_server.key >tian_server.csr
(如果不加-config .openssl.cnf參數的話,常會報Unable to load config info from …/ssl/openssl.cnf)
之後就會要求輸入一系列的參數:
Country Name (2 letter code) [AU]:CN ISO 國家代碼(只支持兩位字元)
State or Province Name (full name) [Some-State]:GD 所在省份
Locality Name (eg, city) []:GZ 所在城市
Organization Name (eg, company): 公司名稱
Organizational Unit Name (eg, section) []: 組織名稱
Common Name (eg, YOUR name) []: 申請證書的域名(建議和httpd.conf中serverName必須一致)
Please enter the following 『extra』 attributes to be sent with your certificate request A challenge password []: 交換密鑰 (隨意寫)
An optional company name []:(建議和httpd.conf中serverName必須一致)
註:Common Name建議和httpd.conf中serverName必須一致,否則有可能導致apache不能啟動(啟動 apache 時錯誤提示為:server RSA certificate CommonName (CN) `Kedou』 does NOT match server name!? )
完成簽署的server.csr配置。
步驟三:
簽署伺服器證書文件 server.crt
在 bin/目錄下執行命令:
openssl req -x509 -days 5000 -config openssl.cnf -key tian_server.key -in tian_server.csr >tian_server.crt
說明:這是用步驟 1,2 的的密鑰和證書請求生成證書 server.crt,-days 參數 指明證書有效期,單位為天,x509 表示生成的為 X.509 證書。
步驟四:
在bin 目錄下,找到tian_server.crt、tian_server.csr、tian_server.key三個文件,將此三個文件剪切到Apache的conf目錄下。
步驟五:
配置 httpd.conf. 在Apache的confextra目錄下的 httpd_ssl.conf 文件是關於 ssl 的配置,是httpd.conf的一 部分。
在 httpd.conf 中下列兩行:去掉前面的「#」
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
步驟六:
(注意:相同部分被省略掉)
# General setup for the virtual host
DocumentRoot 「D:/PHPStudy/WWW/」(這個地方網頁根目錄)
ServerName phpssl.com:443
ErrorLog 「D:/PHPStudy/Apache/logs/no-robots_error.log.txt」(具體的伺服器上的地址)
TransferLog 「D:/PHPStudy/Apache/logs/no-robots_access.log.txt」(具體的伺服器上的地址)
SSLCertificateFile 「D:/PHPStudy/Apache/conf/tian_server.crt」
SSLCertificateKeyFile 「D:/PHPStudy/Apache/conf/tian_server.key」
CustomLog 「D:/PHPStudy/Apache/logs/ssl_request.log」
「%t %h %x %x 」%r」 %b」
以上最容易出問題的地方是http_ssl.conf中的日誌等路徑問題,建議按照物理路徑進行設置
步驟七:
調試運行Apache,對於Apache。如果是集成板的如xampp,wampserver,或者phpstudy啟動Apache Server,可能我們不知道我們的伺服器出現了什麼問題,建議查看 Apache/logs下的日誌,在此基礎上,配合Cmd命令行在bin目錄下運行httpd命令,如果不報錯,說明伺服器運行沒問題,否則更具提示修改問題。
文章轉載:https://www.trustauth.cn/wiki/21869.html
※關於linux刪除文件夾命令方法
※網站優化設備——CDN
※網站優化之網頁布局之DIV CSS
※關於log4j.properties 配置說明
※linux與windows系統有什麼區別?
TAG:數安時代GDCA |