1.安裝nginx時(shí)記得--with-http_ssl_module 模塊。
2.創(chuàng)建服務(wù)器證書密鑰文件
#生成密鑰 [root@233 nginx]# openssl genrsa -des3 -out server.key 1024 Generating RSA private key, 1024 bit long modulus .......++++++ ...........++++++ e is 65537 (0x10001) Enter pass phrase for server.key:123456 #設(shè)置密碼 Verifying - Enter pass phrase for server.key:123456 #再次設(shè)置密碼 #生成證書認(rèn)證文件 [root@233 nginx]# openssl req -new -key server.key -out server.csr Enter pass phrase for server.key:123456 #上面設(shè)置的密碼 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) [XX]:CN #國家 State or Province Name (full name) []:guangdong #省 Locality Name (eg, city) [Default City]:guangzhou #市 Organization Name (eg, company) [Default Company Ltd]:richinfo #公司 Organizational Unit Name (eg, section) []: #組織,可以不寫 Common Name (eg, your name or your server's hostname) []:www.aaa.com #域名,這個(gè)域名記得nginx配置的時(shí)候一樣 Email Address []: #郵箱,可以不寫 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: #不設(shè)置 An optional company name []: #不用寫 [root@233 nginx]# cat server.key -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,D51608920B407C43 ZSorICzxSDp7W+bgoeZEx7RKSOfi220qKgh6EpqWCJOeP4/MnHn6JcuAYdNca+ii UJpHasnMaakCdBHQQxAyU7v7jW1xQAI7ffsncPfKDpBxxZb6WeTrW0F3LVY4rFUC ... bDbUcs/6DZQUc02dBCx3DEIujdL4DJhJbBMc1Y2e/RGHg/jBrV5IA6n1X+vmwfV7 rVPFcxccNZJ6jvilWhCiGwrEcrnCJpOqlj6Ihas6b0fihelVAPWj/Q== -----END RSA PRIVATE KEY----- #拷貝一份密鑰 [root@233 nginx]# cp server.key server.key.org #用備份的密鑰重新生成不帶密碼的密鑰 [root@233 nginx]# openssl rsa -in server.key.org -out server.key Enter pass phrase for server.key.org:123456 #輸入密碼 writing RSA key [root@233 nginx]# cat server.key -----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQDBc+2JL0dWVKOsd9v5zQBSjABG5CRPn+vzfjmtpcjokDBOw0ub 5HADAGueMgEtrbymkpJmabucqrUGfvUAZh7+PSYyDdLjbgoIejfC7yMJyCstrwkN 5UjD8sz1HYOPx1oomlMvFts7+0/PC388gF89a69898PmzKTYc+X0DlNhrwIDAQAB ... z3hnfZ/IGKLkCCyW89ECQQCjo+FkC21Df9A7kyhO0vQ4UEiEINGdlMQhLTBlfMpt BH6zTjfHly0iglV2RrFjmsDGZCNqgAlRED76qD4F+emp -----END RSA PRIVATE KEY----- [root@233 nginx]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt Signature ok subject=/C=CN/ST=guangdong/L=guangzhou/O=richinfo/CN=www.aaa.com Getting Private key
3.在nginx上設(shè)置反向代理轉(zhuǎn)發(fā)
http{ ........... server { listen 443 ssl http2; ssl_certificate /home/nginx/server.crt; ssl_certificate_key /home/nginx/server.key; server_name www.aaa.com; location / { proxy_pass https://192.168.xx.xxx:10443/; #這個(gè)就算要代理的地址 } } ........... }
4.訪問測(cè)試
(1)直接用IP訪問

(2)本機(jī)配置host,然后用域名訪問
192.168.xx.233 www.aaa.com
作者:陳耿聰 —— 夕獄
出處:http://www.rzrgm.cn/CGCong/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
浙公網(wǎng)安備 33010602011771號(hào)