阿里雲服務器Centos上Apache安裝SSL證書配置Https

首先咱們先去阿里雲申請一個免費的SSL證書(https://common-buy.aliyun.com/?spm=5176.7968328.1266638..5e971232BzMSp5&commodityCode=cas#/buy)以下圖:服務器

申請經過以後,簽發了證書,咱們就去控制檯下載,下載Apache版本的證書就行了ide

而後在服務器的httpd目錄下面新建一個cert的文件夾,把下載好的證書經過ftp放到該文件夾下面:ui

而後確保服務器安裝了openssl和openssl-devel,httpd-devel,沒有安裝的話用yum安裝一下就行了阿里雲

yum install openssl;
yum install openssl-devel;
yum install httpd-devel;

而後去配置Apache的配置文件httpd.confspa

LoadModule ssl_module modules/mod_ssl.so   #去掉前面的註釋,沒有的話就本身加上去加載ssl模塊,去modules文件夾下面能找到mod_ssl.so文件,若是沒有那就是mod_ssl模塊沒有安裝正確
Include conf/extra/httpd-ssl.conf   #去掉註釋,沒有這個文件的話就去conf.d下面找ssl.conf是同樣的導入進來就行了,自行把路徑替換一下,沒有的話本身建一個
#在文件尾加入下面的配置,能夠讓http重定向httpds
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]

而後去配置ssl.conf(httpd-ssl.conf)3d

SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:
SSLHonorCipherOrder on 
#在頁面底部配置VirtualHost以下,若是有多個證書能夠配置多個VirtualHost
<VirtualHost *:443>
	 DocumentRoot "項目地址絕對路徑"
	 ServerName https://域名
	 ServerAlias https://域名
	 SSLEngine on
	 SSLProtocol all -SSLv2 -SSLv3
	 SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:
	 SSLCertificateFile 證書公鑰文件絕對路徑
	 SSLCertificateKeyFile 證書私鑰文件絕對路徑
	 SSLCertificateChainFile 證書鏈絕對路徑
	  
	 <Directory "項目絕對路徑">
	 Options FollowSymLinks ExecCGI
	 AllowOverride All
	 Order allow,deny
	 Allow from all
	 Require all granted
	 </Directory>
</VirtualHost> 

 記得在httpd.conf裏面也配置一個同項目的VirtualHostrest

作完上面這些步驟記得要開放HTTPS默認的443端口,而後重啓Apache服務器就完成https的配置了blog

service httpd restart
相關文章
相關標籤/搜索