如何在阿里雲裏申請並使用免費https證書SSL、nginx下配置https證書

  目前網站SSL證書基本已經普及了,不少站點基本都安裝了SSL證書,並且目前無論是國內比較知名的雲商家基本都提供免費的SSL證書。本次說的是阿里雲提供的免費ssl證書。javascript

  廢話很少說,直接上步驟:css

  一、登陸阿里雲控制檯:https://www.aliyun.com/,點開產品服務->安全(雲盾)->SSL證書(應用安全),如圖:html

  

  二、進入以後點擊右上角「購買證書」java

  

  三、選擇品牌「Symantec」-->選擇保護類型「1個域名」,這時候纔會出現證書類型「免費型DV SSL」,選擇這個免費的便可nginx

  

 

   四、選好以後點擊購買便可ubuntu

  

  五、付完款以後返回證書控制檯vim

  

  六、點擊申請,按照需求填寫相關信息,而後點下一步,驗證便可。提交審覈後稍等幾分鐘就能經過審覈了。安全

  

  證書經過以後,接下來就是配置的事了。這裏以nginx爲例。服務器

  一、下載證書-->選擇須要的服務器類型,這裏以nginx爲例。微信

  

  二、下載好以後登錄服務器,打開nginx目錄/usr/local/nginx,新建一個文件夾cert,講證書解壓後放進cert文件夾內。

   

  三、配置nginx 

server {
       		listen       443 ssl;
		#listen  	80;
      		server_name  www.zhudada.online;
		ssl_certificate      /usr/local/nginx/cert/1631577_zhudada.online.pem;
        
		ssl_certificate_key  /usr/local/nginx/cert/1631577_zhudada.online.key;

        	
		ssl_session_cache    shared:SSL:1m;
        
		ssl_session_timeout  5m;

        
		ssl_ciphers  HIGH:!aNULL:!MD5;
        
		ssl_prefer_server_ciphers  on;

		location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) {
			root /home/zhudada;
			index index.html;
       		 }
    		   # location / {
      		  	#    proxy_set_header Host       $host;
       			  #   proxy_pass        http://47.107.99.77:80/index.html;
       		# }
    	}

  四、重啓nginx便可。

  

 

 

  到這裏須要注意幾個問題:

  一、Nginx若是未開啓SSL模塊,配置Https時提示錯誤。

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx

  這是因爲nginx缺乏http_ssl_module模塊,編譯安裝的時候帶上--with-http_ssl_module配置就好了,解決步驟:

    1:進入到源碼包,如:

cd /root/nginx-1.15.6/

    2:查看nginx原有的模塊

/usr/local/nginx/sbin/nginx -V

    3:查看configure arguments:後邊有沒有值,若是有,就複製下來。而後執行

./configure --原來有的模塊(若是有的話) --with-http_ssl_module

    4:執行make

make

    5:關閉如今運行的Nginx服務器

/usr/local/nginx/sbin/nginx -s stop

      提示:若是此時報錯nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx,則先把有關https的配置註釋再關閉。

    6:執行

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak  

    7:將新的 nginx 覆蓋舊安裝目錄,執行

cp objs/nginx /usr/local/nginx/sbin/nginx 

    8:最後重啓一下nginx便可

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    驗證一下:輸入/usr/local/nginx/sbin/nginx -V,這時會出現下面這種狀況,說明已經成功了,能夠用https訪問你的網站了:

  

 

  補充幾點:

  一、在上面第3步執行./configure的時候可能會出現如下報錯:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

  解決方法: 
  Centos須要安裝openssl-devel 
  Ubuntu則須要安裝:sudo apt-get install libssl-dev

  這時若是報錯 Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

  解決方法:

  第一種:

 

  sudo vim /etc/resolv.conf 

 

  添加nameserver 8.8.8.8

 

  第二種:

 

  /etc/apt/sources.list 的內容換成  

 

  deb http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse

 

  deb-src http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse

 

  deb http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse

 

  deb-src http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse

 

  deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse

 

  deb-src http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse

 

  deb http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse

 

  deb-src http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse

 

  deb http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse

 

  deb-src http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse

 

  而後sudo apt-get update一下就好了。

 

  二、nginx配置輸入網址後默認跳轉至https站點

     server {
		listen 80;
		server_name www.zhudada.online;
		rewrite ^(.*) https://$server_name$1 permanent;
	}
	server {
       		listen       443 ssl;
		#listen  	80;
      		server_name  www.zhudada.online;
		ssl_certificate      /usr/local/nginx/cert/1631577_zhudada.online.pem;
        
		ssl_certificate_key  /usr/local/nginx/cert/1631577_zhudada.online.key;

        	
		ssl_session_cache    shared:SSL:1m;
        
		ssl_session_timeout  5m;

        
		ssl_ciphers  HIGH:!aNULL:!MD5;
        
		ssl_prefer_server_ciphers  on;

		location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) {
			root /home/zhudada;
			index index.html;
       		 }
    		   # location / {
      		  	#    proxy_set_header Host       $host;
       			  #   proxy_pass        http://47.107.99.77:80/index.html;
       		# }
    	}

  

 

  到這裏就結束了,若是安裝配置過程當中有任何問題,能夠問我

  qq: 412606846(微信同號)

相關文章
相關標籤/搜索