環境:
- 1臺 CentOS Linux release 7.5.1804 (Core)
關閉防火墻和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 創建私鑰
[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引數指明證書有效期,單位為天
x509表示生成的為X.509證書
以上簽署證書僅僅做測驗用,真正運行的時候,應該將CSR發送到一個CA回傳真正的證書
用openssl x509 -noout -text -in server.crt 可以查看證書的內容,證書實際上包含了Public Key
@2.3 生成無密的私鑰
[root@localhost sslkey]# openssl rsa -in server.key -out server.key.unsecure

查看生成證書與私鑰檔案

3、nginx配置https
@3.1 修改配置nginx.conf,將監聽埠80替換成443,配置ssl認證
[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 瀏覽器訪問即可!

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/206132.html
標籤:其他
上一篇:在LIUNX下的檔案定時備份操作
