1. 程式人生 > >nginx怎麼配置https

nginx怎麼配置https

一 .配置域名  生成證書

生成證書:[ 我們的證書放在nginx/conf/ssl目錄]

1.建立伺服器證書金鑰檔案 server.key:

openssl genrsa -des3 -out server.key 1024

輸入密碼,確認密碼,自己隨便定義,但是要記住,後面會用到。

2.建立伺服器證書的申請檔案 server.csr

openssl req -new -key server.key -out server.csr

輸出內容為:
Enter pass phrase for root.key: ← 輸入前面建立的密碼 
Country Name (2 letter code) [AU]:CN ← 國家代號,中國輸入CN 
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音 
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名 
Organizational Unit Name (eg, section) []: ← 可以不輸入 
Common Name (eg, YOUR name) []: ← 此時不輸入 
Email Address []:

[email protected] ← 電子郵箱,可隨意填
Please enter the following ‘extra’ attributes 
to be sent with your certificate request 
A challenge password []: ← 可以不輸入 
An optional company name []: ← 可以不輸入

4.備份一份伺服器金鑰檔案    去除檔案口令

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

5.生成證書檔案server.crt

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

重啟後報錯 [原因 : 編譯安裝nginx時沒有載入ssl模組]

2.檢視安裝模組

3.進入安裝包 再次執行configure [ 安裝統計模組 和ssl模組]

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

4.重新編譯[ 執行 make ],不需要make  install安裝。否則會覆蓋

5.備份已安裝的nginx

6.將剛剛編譯好的nginx覆蓋掉原來的nginx(ngixn必須停止)

7.訪問https 和http