環(huán)境:
1臺(tái) 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 目錄、做個(gè)軟鏈接
[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證書
以上簽署證書僅僅做測(cè)試用,真正運(yùn)行的時(shí)候,應(yīng)該將CSR發(fā)送到一個(gè)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 啟動(dòng) 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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!