1. 程式人生 > >設定APACHE支援SSL

設定APACHE支援SSL

總體分兩步:一、生成SSL證書;二、設定Apache的SSL配置

1.   安裝openssl

yum install mod_ssl openssl

2.    生成自簽名的證書

  1. #Generate private key   
  2. openssl genrsa -out ca.key 2048   
  3. #Generate CSR Certificate Signing Request   
  4. openssl req -new -key ca.key -out ca.csr  
  5. #Generate Self Signed Certificate  
  6. openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt  

3.    證書放到規範的目錄中

  1. #Copy the files to the correct locations  
  2. cp ca.crt /etc/pki/tls/certs  
  3. cp ca.key /etc/pki/tls/private/ca.key  
  4. cp ca.csr /etc/pki/tls/private/ca.csr  

4.    修改Apache的SSL配置

Edit the Apache SSL configuration file /etc/httpd/conf.d/ssl.conf.

Change the paths to match where the Keyfile is stored.

  1. SSLCertificateFile /etc/pki/tls/certs/ca.crt  

Then set the correct path for theCertificate Key File a few lines below.

  1. SSLCertificateKeyFile /etc/pki/tls/private/ca.key  

Quit and save the file.

5.    重啟Apache

  1. service httpd restart  

All being well you should now be ableto connect over https to your server. As the certificate is self signedbrowsers will generally ask you whether you want to accept the certificate.