nginx生成自簽名SSL證書配置HTTPS的實(shí)現(xiàn)
一、安裝nginx
nginx必須有"--with-http_ssl_module"模塊 查看nginx安裝的模塊: root@ecs-7398:/usr/local/nginx# cd /usr/local/nginx/ root@ecs-7398:/usr/local/nginx# ./sbin/nginx -V nginx version: nginx/1.20.2 built by gcc 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-pcre --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module --with-http_realip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module
二、創(chuàng)建證書
1、生成私鑰
root@ecs-7398:~# cd /usr/local/nginx/ root@ecs-7398:/usr/local/nginx# mkdir key root@ecs-7398:/usr/local/nginx# cd key/ root@ecs-7398:/usr/local/nginx/key# openssl genrsa -des3 -out server.key 2048 #使用ssl生成私鑰名為 server.key Generating RSA private key, 2048 bit long modulus (2 primes) ................+++++ ......+++++ e is 65537 (0x010001) Enter pass phrase for server.key: #自定義密碼:123456 Verifying - Enter pass phrase for server.key: #確認(rèn)密碼:123456 root@ecs-7398:/usr/local/nginx# ls client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp server.key uwsgi_temp root@ecs-7398:/usr/local/nginx/key# cat server.key #查看私鑰內(nèi)容 -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,4103533ED9B6ECD1 MAhsh46L3TsiCymB5pTA93lw/WZKzX/9iuzgM/OgG7U0cKHWdiLf907/52Ocp80e bY/FKTADBcrEv2uFuke28WjdN2aQddiJGsP0CDLVKfv/kqEgvYuy2sIcoXcHV8fL 70vfaFuTa5CwxyIbRvfHFSpj39oC76eitx120x+KCkgWDkIaVGG9cP0TfmDnDOSe fmpmZhqkkkP5dXuuPNItfumHHhZpjXqMr9oGxtENdMyNBrRywC8+NhRhO7iomZeP tHiQpjQCrD8xkKcYqfKVCOS8KCXeKF1EylbJ89e2ZqgaujuKyC90raHpwga9MUSO HNOT/U85zwsmqkh4/2Ox7AVLlNiG0+Rxt+IfWJb6xgT21SEfL/2vskNAkj2PN3J+ mpeSvpaKI1BsZ8LrpsqFNR0fDhIg+a5hzfSTlWouZcpePx7vB5qvKAvoSKrGmbDO GQp4H24cSPAaQI6Wih+AxB8stfTCsBatJ5RwXgYNskumHL8KzpC9/Yj7QrLx3m3I TBDlpOVU6tUYzMDVYDMGtTUhoPIdfVjaRz8BGWUFp0MM3Sx+rppPul1voSuVve5T 8uba4fqv+KIEQdR/PELB4N+ZgZiFP5HtoZN7mFWN6H/Ygm3GEgNeljiqypYQpZOd dUIC/vhRsCuylww7Rh8LUtgnVAkJbyuqjA38wypATLKQFI1rwFzI9gCWwyz0SCNQ tffBpZebLkG+H7GGfrTo+50TLDVetyQctbj2ibytpVKK4xE7oaMSZYqbfqg6OYCp k2LhlWkKsDf7XhLbo5kP2UUfB7LSzx3JdRmA0Fw3GqEevFJysyJO2w== -----END RSA PRIVATE KEY----- root@ecs-7398:/usr/local/nginx/key#
2、生成公鑰
root@ecs-7398:/usr/local/nginx/key# openssl req -new -key server.key -out server.csr #基于創(chuàng)建的server.key私鑰創(chuàng)建server.csr公鑰 Enter pass phrase for server.key: #輸入server.key的密碼:123456 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN #國(guó)家 State or Province Name (full name) [Some-State]:shanghai #省市 Locality Name (eg, city) []:jiading #城市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:bai #組織 Organizational Unit Name (eg, section) []:zr #單位 Common Name (e.g. server FQDN or YOUR name) []:byc #姓名 Email Address []:2123288207@qq.com #郵箱 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:123456 #密碼 An optional company name []:zr #公司 root@ecs-7398:/usr/local/nginx/key#
3、簽名生成證書
root@ecs-7398:/usr/local/nginx/key# openssl rsa -in server.key -out server.key #去除server.key認(rèn)證,避免每次"nginx -t"時(shí)出現(xiàn)輸入密碼的情況 Enter pass phrase for server.key: #密碼:123456 writing RSA key root@ecs-7398:/usr/local/nginx/key# root@ecs-7398:/usr/local/nginx/key# openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt #使用私鑰和公鑰生成server.crt簽名證書,-days為3650天 -in指定公鑰,-signkey指定私鑰,生成的前面證書為server.crt Signature ok subject=C = CN, ST = shanghai, L = jiading, O = bai, OU = zr, CN = byc, emailAddress = 2123288207@qq.com Getting Private key root@ecs-7398:/usr/local/nginx/key#
三、配置證書并驗(yàn)證
root@ecs-7398:/usr/local/nginx/key# cd .. root@ecs-7398:/usr/local/nginx# systemctl start nginx #啟動(dòng)Nginx root@ecs-7398:/usr/local/nginx# vim conf/nginx.conf #編輯nginx主配置文件將后面server的注釋去掉
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/key/server.crt; ##證書路徑
ssl_certificate_key /usr/local/nginx/key/server.key; ##證書路徑
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/nginx/html/xiaomi;
index index.html index.htm;
}
}
四、測(cè)試
root@ecs-7398:/usr/local/nginx# cd root@ecs-7398:~# ls nginx-1.20.2 nginx-1.20.2.tar.gz 小米官網(wǎng).zip root@ecs-7398:~# unzip 小米官網(wǎng).zip -d /usr/local/nginx/html/xiaomi root@ecs-7398:~# ls /usr/local/nginx/html/xiaomi/ css iconfont images index.html
在瀏覽器訪問(wèn)https//xxx.xxx.xxx.xxx:443


到此這篇關(guān)于nginx生成自簽名SSL證書配置HTTPS的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)nginx生成自簽名SSL證書內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Nginx配置ssl證書(https)的全過(guò)程
- Nginx實(shí)現(xiàn)自簽名SSL證書生成與配置實(shí)現(xiàn)
- nginx配置ssl實(shí)現(xiàn)https訪問(wèn)(小白文)
- nginx和Apache配置SSL證書的實(shí)現(xiàn)步驟
- Nginx配置SSL證書的方法步驟
- nginx配置SSL/TLS證書的實(shí)現(xiàn)步驟
- Nginx配置ssl支持https全過(guò)程(docker版)
- Nginx SSL/TLS配置的實(shí)現(xiàn)
- Nginx配置SSL證書的全流程
- Nginx SSL配置錯(cuò)誤問(wèn)題及解決
相關(guān)文章
負(fù)載均衡的基本知識(shí)以及使用nginx進(jìn)行負(fù)載均衡的簡(jiǎn)單例子
今天小編就為大家分享一篇關(guān)于負(fù)載均衡的基本知識(shí)以及使用nginx進(jìn)行負(fù)載均衡的簡(jiǎn)單例子,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
使用Nginx Ingress 優(yōu)雅顯示錯(cuò)誤頁(yè)面
這篇文章主要為大家介紹了使用Nginx Ingress 優(yōu)雅顯示錯(cuò)誤頁(yè)面實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09
Forever+nginx部署Node站點(diǎn)的方法示例
這篇文章主要介紹了Forever+nginx部署Node站點(diǎn)的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
一篇文章快速掌握Nginx部署前端項(xiàng)目(Nginx安裝配置及部署都非常詳細(xì)!)
這篇文章主要給大家介紹了關(guān)于如何通過(guò)一篇文章快速掌握Nginx部署前端項(xiàng)目的相關(guān)資料,文中從Nginx安裝配置及部署都非常詳細(xì)哦,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-01-01
Nginx服務(wù)器實(shí)現(xiàn)通過(guò)ip和user_gent限制訪問(wèn)的方法分析
這篇文章主要介紹了Nginx服務(wù)器實(shí)現(xiàn)通過(guò)ip和user_gent限制訪問(wèn)的方法,結(jié)合實(shí)例形式分析了Nginx通過(guò)限制ip和user_gent限制訪問(wèn)來(lái)過(guò)濾DDOS攻擊的相關(guān)操作技巧,需要的朋友可以參考下2019-07-07

