Nginx SSLÉèÖý̳̣¬°ü¹ÜÍøÕ¾Ç徲ͨѶ
nginx sslÉèÖý̳̣¬°ü¹ÜÍøÕ¾Ç徲ͨѶ
Ëæ×Å»¥ÁªÍøµÄÉú³¤£¬ÈËÃÇÔ½À´Ô½ÖØÊÓÍøÕ¾µÄÇå¾²ÐÔ£¬ÌØÊâÊÇÔÚÊý¾Ý´«ÊäÀú³ÌÖС£SSL£¨Secure Sockets Layer£©ÐÒéÊÇÒ»ÖÖ³£ÓõļÓÃÜͨѶÐÒ飬ͨ¹ýSSLÉèÖ㬿ÉÒÔ°ü¹ÜÍøÕ¾Óë»á¼ûÕßÖ®¼äµÄÊý¾Ý´«ÊäÇå¾²¡£±¾ÎĽ«Îª¸÷ÈËÏÈÈÝÔõÑùÔÚNginxÖÐÉèÖÃSSL£¬ÒÔÌáÉýÍøÕ¾µÄÇå¾²ÐÔ¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪ׼±¸Ò»¸öSSLÖ¤Êé¡£SSLÖ¤ÊéÊÇÒ»ÖÖÓÃÓÚÑéÖ¤ÍøÕ¾Éí·Ý²¢¼ÓÃÜÊý¾Ý´«ÊäµÄÊý×ÖÖ¤Ê顣ͨ³£ÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒÔ´ÓȨÍþµÄSSLÖ¤ÊéÌṩÉ̹ºÖÃÓÐÓõÄSSLÖ¤Ê飬ÈçLet’s Encrypt¡¢ComodoµÈ¡£ÔÚ¹ºÖÃÖ¤Êéºó£¬ÎÒÃÇÐèÒª½«Ö¤ÊéÎļþÏÂÔص½Ð§ÀÍÆ÷ÉÏ¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓSSLÉèÖ᣷¿ªNginxµÄÉèÖÃÎļþ£¨Í¨³£Î»ÓÚ /etc/nginx/nginx.conf »ò /etc/nginx/conf.d/default.conf£©£¬²¢Ìí¼ÓÒÔÏÂʾÀý´úÂ룺
server { listen 443 ssl; server_name example.com; ssl_certificate /path/to/certificate.crt; ssl_certificate_key /path/to/private.key; location / { #ÆäËûNginxÉèÖà } }
µÇ¼ºó¸´ÖÆ
ÔÚ´úÂëÖУ¬ÎÒÃÇÊ×ÏȽ«¼àÌý¶Ë¿ÚÉèÖÃΪ443£¬ÕâÊÇHTTPSÐÒéµÄĬÈ϶˿ڡ£È»ºó£¬ÎÒÃÇÖ¸¶¨ÁËЧÀÍÆ÷µÄÓòÃû¡£ssl_certificateºÍssl_certificate_key»®·ÖÖ¸¶¨ÁËSSLÖ¤ÊéºÍ˽ԿµÄ·¾¶¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª±à¼NginxµÄÈ«¾ÖÉèÖÃÎļþ£¬ÆôÓÃSSLÐæźͼÓÃÜËã·¨¡£·¿ªNginxµÄÈ«¾ÖÉèÖÃÎļþ£¨Í¨³£Î»ÓÚ /etc/nginx/nginx.conf£©£¬²¢Ìí¼ÓÒÔÏÂʾÀý´úÂ룺
ssl_protocols TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5;
µÇ¼ºó¸´ÖÆ
ÔÚ´úÂëÖУ¬ÎÒÃÇÖ¸¶¨ÁËʹÓÃTLSv1.2ÐÒé¾ÙÐÐSSLͨѶ£¬²¢½ûÓÃÁ˲»Çå¾²µÄ¼ÓÃÜËã·¨¡£
³ýÁË»ù±¾µÄSSLÉèÖã¬ÎÒÃÇ»¹¿ÉÒÔͨ¹ý¸ü¶àµÄÉèÖÃÑ¡ÏîÀ´½øÒ»²½ÌáÉýÍøÕ¾µÄÇå¾²ÐÔ¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÆôÓÃHSTS£¨HTTP Strict Transport Security£©»úÖÆ£¬Ç¿ÖÆ¿Í»§¶ËʹÓÃHTTPS»á¼ûÍøÕ¾¡£ÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÒÔÏÂʾÀý´úÂ룺
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
µÇ¼ºó¸´ÖÆ
Õ⽫ÆôÓÃHSTS»úÖÆ£¬²¢Ö¸¶¨ä¯ÀÀÆ÷ÔÚÒ»ÄêÄÚÇ¿ÖÆʹÓÃHTTPS»á¼ûÍøÕ¾£¬°üÀ¨ËùÓÐ×ÓÓòÃû¡£
ÁíÍ⣬ÎÒÃÇ»¹¿ÉÒÔÉèÖÃSSLÎÕÊÖÀú³ÌÖеļÓÃÜËã·¨ÓÅÏȼ¶¡£ÔÚNginxµÄÉèÖÃÎļþÖÐÌí¼ÓÒÔÏÂʾÀý´úÂ룺
ssl_prefer_server_ciphers on; ssl_dhparam /path/to/dhparam.pem;
µÇ¼ºó¸´ÖÆ
Õ⽫ÆôÓÃЧÀÍÆ÷¶Ë¼ÓÃÜËã·¨ÓÅÏȼ¶£¬²¢Ö¸¶¨Diffie-Hellman£¨DH£©ÃÜÔ¿½»Á÷²ÎÊýµÄ·¾¶¡£
Íê³ÉÒÔÉÏÉèÖúó£¬ÉúÑIJ¢¹Ø±ÕNginxÉèÖÃÎļþ¡£È»ºó£¬Ê¹ÓÃÒÔÏÂÏÂÁîÖØÆôNginxЧÀÍ£¬Ê¹ÉèÖÃÉúЧ£º
sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
¹§Ï²£¡ÏÖÔÚÄúµÄÍøÕ¾ÒѾÉèÖÃÁËSSL£¬²¢ÇÒ¿ÉÒÔͨ¹ýHTTPS»á¼û¡£Í¨¹ýSSLÉèÖã¬Äú¿ÉÒÔ°ü¹ÜÍøÕ¾Óë»á¼ûÕßÖ®¼äµÄÊý¾Ý´«ÊäÇå¾²£¬ÌáÉýÍøÕ¾µÄÇå¾²ÐÔ¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùÔÚNginxÖÐÉèÖÃSSL£¬ÒÔÌáÉýÍøÕ¾µÄÇå¾²ÐÔ¡£Í¨¹ýѧϰSSLÉèÖã¬ÎÒÃÇ¿ÉÒÔÈ·±£ÍøÕ¾Óë»á¼ûÕßÖ®¼äµÄÊý¾Ý´«ÊäÇå¾²£¬²¢±£»¤Óû§µÄÒþ˽ÐÅÏ¢¡£Ï£Íû±¾ÎĶԸ÷ÈËÓÐËù×ÊÖú£¬ÎªÍøÕ¾Ìṩ¸üºÃµÄÇå¾²°ü¹Ü¡£
ÒÔÉϾÍÊÇNginx SSLÉèÖý̳̣¬°ü¹ÜÍøÕ¾Ç徲ͨѶµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡