sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
關於參數:node
參考:https://blog.csdn.net/zstack_org/article/details/70048745linux
sudo lnmp ssl add
響應:nginx
+-------------------------------------------+ | Manager for LNMP, Written by Licess | +-------------------------------------------+ | https://lnmp.org | +-------------------------------------------+ Please enter domain(example: www.lnmp.org): localhost Your domain: localhost Enter more domain name(example: lnmp.org *.lnmp.org): Please enter the directory for domain localhost: /home/wwwroot/www Allow access log? (y/n) y Enter access log filename(Default:localhost.log): You access log filename: localhost.log Please enter Administrator Email Address: ××××@163.com Server Administrator Email:××××@163.com 1: Use your own SSL Certificate and Key 2: Use Let's Encrypt to create SSL Certificate and Key Enter 1 or 2: 1 Please enter full path to SSL Certificate file: /etc/ssl/certs/apache-selfsigned.crt Please enter full path to SSL Certificate Key file: /etc/ssl/private/apache-selfsigned.key Please enter full path to SSL Chain file: SSL Chain file will not set.Test Apache configure file...
重啓電腦apache 沒法訪問,可經過命令進行查看錯誤。git
httpd -k start
AH00112: Warning: DocumentRoot [/home/wwwroot/default] does not exist AH00526: Syntax error on line 23 of /usr/local/apache/conf/vhost/localhost.conf: SSLCertificateKeyFile: file '/etc/ssl/private/apache-selfsigned.key' does not exist or is empty
解決:github
/home/wwwroot/default 目錄不存在,vhost若是沒有指定path,在/usr/local/apache/conf/extra/httpd-vhosts.conf 中修改。
/etc/ssl/private/apache-selfsigned.key 不存在,是由於www-data 組沒有讀取/etc/ssl的全選。apache
sudo chmod -755 /etc/ssl/*
自簽證書很簡單,但生成的不被瀏覽器承認,在地址欄顯示爲 「不安全」。瀏覽器
有一個開源工具,mkcert ,由google Go 團隊開發,生成可被瀏覽器信任的證書。原理是生成證書的同時生成本身的證書頒發機構CA, 在系統裏插入一個本身的 CA root,信任這個 CA root,而後用這個根生成 SAN 證書。安全
github地址: https://github.com/FiloSottile/mkcert服務器
可經過項目github的Releases打包文件直接運行生成;app
./mkcert-v1.3.0-linux-amd64
是步驟幫助說明:
Using the local CA at "/home/×××/.local/share/mkcert" ✨ Usage of mkcert: $ mkcert -install Install the local CA in the system trust store. $ mkcert example.org Generate "example.org.pem" and "example.org-key.pem". $ mkcert example.com myapp.dev localhost 127.0.0.1 ::1 Generate "example.com+4.pem" and "example.com+4-key.pem". $ mkcert "*.example.it" Generate "_wildcard.example.it.pem" and "_wildcard.example.it-key.pem". $ mkcert -uninstall Uninstall the local CA (but do not delete it). For more options, run "mkcert -help".
執行 ./mkcert-v1.3.0-linux-amd64 --install 就會安裝本地的私有CA,並添加系統信任此CA。
執行 ./mkcert-v1.3.0-linux-amd64 localhost 生成 The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅ 將證書添加nginx或apache便可。
參考: https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/