1. 程式人生 > >阿里雲伺服器centos7.4作業系統Apache配置https服務

阿里雲伺服器centos7.4作業系統Apache配置https服務

原文地址:https://blog.csdn.net/qq_35399846/article/details/79247239

檔案說明:

  1. 證書檔案xxxxxxxxxxxxxx.pem,包含兩段內容,請不要刪除任何一段內容。
  2. 如果是證書系統建立的CSR,還包含:證書私鑰檔案xxxxxxxxxxxxxx.key、證書公鑰檔案public.pem、證書鏈檔案chain.pem。
  3. 證書是在阿里雲的CA證書服務裡下載的

準備工作:

1.安裝:

#yum -y install httpd httpd-devel
#yum -y install openssl openssl-devel
#yum -y install mod_ssl

2.防火牆的開啟以及開放80、443埠:

#systemctl start firewalld.service
#netstat -tnl    //檢視埠的監聽狀態 
#firewall-cmd --zone=public --add-port=80/tcp --permanent
success
#firewall-cmd --zone=public --add-port=443/tcp --permanent
success
#firewall-cmd --reload

配置

( 1 ) 在Apache的安裝目錄下建立cert目錄,並且將下載的全部檔案拷貝到cert目錄中。如果申請證書時是自己建立的CSR檔案,請將對應的私鑰檔案放到cert目錄下並且命名為xxxxxxxxxxxxxx.key;

( 2 ) 開啟 apache 安裝目錄下 conf 目錄中的 httpd.conf 檔案,新增以下內容:

#Include conf.d/*.conf

 

( 3 ) 修改ssl配置:

#vim /etc/httpd/conf.d/ssl.conf
# 新增 SSL 協議支援協議,去掉不安全的協議
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件如下
SSLCipherSuite (按照阿里雲給的來)
SSLHonorCipherOrder on
# 證書公鑰配置
SSLCertificateFile cert/public.pem
# 證書私鑰配置
SSLCertificateKeyFile (按照阿里雲給的來)
# 證書鏈配置,如果該屬性開頭有 '#'字元,請刪除掉
SSLCertificateChainFile cert/chain.pem

 

( 4 ) 重啟 Apache。

檢視80、443埠是否開啟:

可以通過訪問站長之家http://tool.chinaz.com/port/

出現錯誤:

1 . make_sock:could not bind to address 0.0.0.0:443

#vim /etc/httpd/conf.d/ssl.conf
進入後將下列註釋
#LoadModule ssl_module modules/mod_ssl.so   
#Listen 443 

2 . 啟動apache時,出現httpd: Could not reliably determine the server\’s fully qualified domain name, using x.x.x.x for ServerName

通過vi開啟apache的配置檔案httpd.conf
#vi /data/apache/conf/httpd.conf
2、找到#ServerName www.example.com:80這行,去掉前面的#號,修改如下:
ServerName x.x.x.x :80

3 . 阿里雲伺服器443埠的開啟真的要命啊。。一直無法開啟不知道是怎麼回事,結果看了很多資料,瞭解了後,發現443埠根本沒監聽,也就是說httpd預設開啟的是80埠,那麼把httpd.conf中的listen 80修改為listen 443。

4 . 出現403錯誤:站點目錄下無首頁檔案(index檔案),而apache的配置又禁止了目錄瀏覽

總結

鬧心了很久的就是埠的開啟了,還是小白,理論知識不足。。。