同事測(cè)試一ssl加密接口,,但是負(fù)責(zé)該接口的同事有事請(qǐng)假了沒在,,所以我就臨時(shí)給配置了一個(gè)https服務(wù),寫了一個(gè)簡單接口供同事使用,,配置nginx的https記錄一下:
一,、生成私鑰和證書
創(chuàng)建帶密鑰口令的私鑰
root@mysqlmaster:/tmp# openssl genrsa -des3 -out ng.key 1024
Generating RSA private key, 1024 bit long modulus
........++++++
...........................................++++++
e is 65537 (0x10001)
Enter pass phrase for ng.key: 輸入口令
Verifying - Enter pass phrase for ng.key: 確認(rèn)口令
二、創(chuàng)建csr文件
root@mysqlmaster:/tmp# openssl req -new -key ng.key -out ng.csr
Enter pass phrase for ng.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:國家 如cn,,hk
State or Province Name (full name) [Some-State]:州或省的名稱 如Beijing
Locality Name (eg, city) []:什么地方級(jí)別,,是城市還是鄉(xiāng)鎮(zhèn)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:什么組織,如公司,,政府
Organizational Unit Name (eg, section) []:組織單位名稱
Common Name (eg, YOUR name) []:名字
Email Address []:郵件地址
Please enter the following 'extra' attributes 額外信息
to be sent with your certificate request
A challenge password []: 復(fù)雜密碼
An optional company name []:
1,,創(chuàng)建私鑰(去除密鑰口令)
openssl rsa -in ng.key -out server.key
輸入口令
2,創(chuàng)建CA證書
openssl req -new -x509 -days 3650 -key server.key -out server.crt
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:
和上面的步驟差不多,,根據(jù)提示輸入證書的信息,,國家,管理人郵件,,姓名,,城市等
三、修改nginx配置文件
root@mysqlmaster:/tmp# cp server.crt server.key /etc/nginx/
默認(rèn)需要證書放到nginx/conf/目錄,,那么
vi /etc/nginx/nginx.conf
增加
listen 443;
server_name localhost;
ssl on;
ssl_certificate server.crt; #證書
ssl_certificate_key server.key; #私鑰
location / {
root html;
index index.html index.htm;
}
}
root@mysqlmaster:/tmp# service nginx restart
重啟服務(wù)