nginx配置https加密訪問的詳細(xì)教程
環(huán)境:
1臺 CentOS Linux release 7.5.1804 (Core)
關(guān)閉防火墻和selinux
開始部署:
1、安裝nginx
@1.1 依賴安裝
yum -y install wget gcc gcc-c++ pcre-devel openssl-devel
@1.2 nginx軟件包下載
wget http://nginx.org/download/nginx-1.19.0.tar.gz
@1.3 解壓、編譯、安裝
[root@localhost ~]# tar xf nginx-1.19.0.tar.gz [root@localhost ~]# cd nginx-1.19.0 [root@localhost nginx-1.19.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module && make && make install
@1.4 切換到 nginx 目錄、做個軟鏈接
[root@localhost nginx-1.19.0]# cd /usr/local/nginx/ [root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
2、配置私鑰和證書
@2.1 創(chuàng)建私鑰
[root@localhost nginx]# mkdir sslkey [root@localhost nginx]# cd sslkey/ [root@localhost sslkey]# openssl genrsa -des3 -out server.key 1024
@2.2 生成證書文件
[root@localhost sslkey]# openssl req -new -key server.key -out server.csr
[root@localhost sslkey]# openssl req -x509 -days 3650 -key server.key -in server.csr > server.crt
-days參數(shù)指明證書有效期,單位為天
x509表示生成的為X.509證書
以上簽署證書僅僅做測試用,真正運(yùn)行的時候,應(yīng)該將CSR發(fā)送到一個CA返回真正的證書
用openssl x509 -noout -text -in server.crt 可以查看證書的內(nèi)容。證書實(shí)際上包含了Public Key
@2.3 生成無密的私鑰
[root@localhost sslkey]# openssl rsa -in server.key -out server.key.unsecure
查看生成證書與私鑰文件
3、nginx配置https
@3.1 修改配置nginx.conf,將監(jiān)聽端口80替換成443,配置ssl認(rèn)證
[root@localhost conf]# pwd /usr/local/nginx/conf [root@localhost conf]# vim nginx.conf
server { listen 443; server_name localhost; ssl_certificate /usr/local/nginx/sslkey/server.crt; ssl_certificate_key /usr/local/nginx/sslkey/server.key.unsecure; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on;
@3.2 啟動 nginx 并查看端口
[root@localhost conf]# nginx [root@localhost conf]# ss -nltp|grep 443 LISTEN 0 128 *:443 *:* users:(("nginx",pid=25949,fd=6),("nginx",pid=25948,fd=6))
4 瀏覽器訪問即可!
到此這篇關(guān)于nginx配置https加密訪問的詳細(xì)教程的文章就介紹到這了,更多相關(guān)nginx配置https加密訪問內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。