網站打不開dns修改嗎深圳搜索引擎優(yōu)化收費
配置Nginx自簽名SSL證書的流程
- 生成一個SSL自簽名證書
- 客戶端機器信任這個自簽名證書
- 修改RHEL服務器的Nginx配置
- 在客戶機用curl測試HTTPS
生成一個SSL自簽名證書
在RHEL服務器上, 用openssl命令生成一個自簽名證書
openssl genrsa -out server.key 2048 #生成一個2048位的RSA私鑰,保存到server.key
openssl req -x509 -new -nodes -key server.key -sha256 -days 3650 -out server.crt -subj "/C=CN/CN=www.petertest.com/O=MyRootCA" # 使用私鑰server.key, 生成一個自簽名的根證書server.crt, 有效期10年
注: CN=www.petertest.com
需要換成你的服務器域名, 否則curl測試會報錯
客戶端機器信任這個自簽名證書
將server.crt傳到客戶端Linux機器上。 在RHEL/Centos機器上, 需要把證書傳到目錄/etc/pki/ca-trust/source/anchors/
,再用如下命令更新系統信任的CA證書列表
update-ca-trust
修改RHEL服務器的Nginx配置
修改nginx.conf
, 如下:
server {listen 443 ssl;server_name www.peter.com; # 設置域名access_log access.log;include /etc/nginx/default.d/*.conf;ssl_certificate /server.crt; # 指定證書的絕對路徑ssl_certificate_key /server.key; # 指定私鑰的絕對路徑location / {default_type text/html;return 200 '<h1>Welcome to Nginx</h1>';}}
再把證書文件server.crt和私鑰文件server.key拷到服務器的根目錄下
測試
在客戶機用curl測試, 返回200 OK
curl https://www.petertest.com:443 -i
HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Wed, 11 Dec 2024 14:02:13 GMT
Content-Type: text/html
Content-Length: 25
Connection: keep-alive<h1>Welcome to Nginx</h1>
參考
https://cloud.tencent.com/developer/article/1743989