生成key文件html
#genrsa 使用idea算法,生成rsa證書,證書名爲 debug.siguoya.name.key,1024表示位數 openssl genrsa -idea -out debug.siguoya.name.key 1024 #設置證書密碼,在生成csr與crt文件的時候須要用到 #Enter pass phrase for debug.siguoya.name.key: #Verifying - Enter pass phrase for debug.siguoya.name.key:
經過key文件,生成csr文件node
openssl req -new -key debug.siguoya.name.key -out debug.siguoya.name.csr Enter pass phrase for debug.siguoya.name.key: #輸入剛纔建立的key文件時設置的密碼便可 Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:GuangDong Locality Name (eg, city) [Default City]:GuangZhou Organization Name (eg, company) [Default Company Ltd]:company Organizational Unit Name (eg, section) []:section Common Name (eg, your name or your servers hostname) []:debug.siguoya.name Email Address []:924714558@qq.com Please enter the following extra attributes to be sent with your certificate request #與上述建立key文件的密碼不同,直接留空便可 A challenge password []: An optional company name []:
將key文件與csr文件進行打包,生成crt文件nginx
#-days指定證書的過時時間,如下指定爲10年 openssl x509 -req -days 3650 -in debug.siguoya.name.csr -signkey debug.siguoya.name.key -out debug.siguoya.name.crt
server{ listen 443 ssl; server_name debug.siguoya.name; ssl_certificate /etc/nginx/debug.siguoya.name.crt; ssl_certificate_key /etc/nginx/debug.siguoya.name.key; location / { root /path/to/project; index index.html; } }
上述配置對於crt證書、pem證書,都適用。配置完以後,須要 nginx -s stop && nginx
。若是訪問時報錯 https Connection refused
,能夠使用nmap
檢查一下服務器是否開放了443端口。算法
配置完成以後,發現每次重啓nginx,都會要求咱們輸入證書的密碼,這個能夠經過以下方式來解決shell
openssl rsa -in ./debug.siguoya.name.key -out ./debug.siguoya.name.nopass.key
而後修改證書文件爲免密碼證書文件segmentfault
ssl_certificate_key /etc/nginx/debug.siguoya.name.nopass.key;
檢測地址1: https://myssl.com/ats.html
檢測地址2: https://www.qcloud.com/produc...
升級 centos7
默認的 openssl 1.0.1
版本centos
wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz tar -zxvf openssl-1.0.2k.tar.gz cd openssl-1.0.2k ./config --prefix=/usr/local/openssl/1.0.2 make && make install mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl /usr/include/openssl.bak ln -s /usr/local/openssl/1.0.2/bin/openssl /usr/bin/openssl ln -s /usr/local/openssl/1.0.2/include/openssl /usr/include/openssl echo '/usr/local/openssl/1.0.2/lib' >> /etc/ld.so.conf ldconfig -v openssl version
#查看openssl版本,OpenSSL 1.0.1e-fips 11 Feb 2013 openssl version #查看哈希算法簽名,sha1WithRSAEncryption openssl x509 -noout -text -in ./debug.siguoya.name.crt
若是生成crt文件時,直接使用keyout選項,則無需在 nginx 重啓的時候,輸入證書密碼跨域
openssl req -x509 -days 3650 -sha256 -nodes -newkey rsa:2048 -keyout debug.siguoya.name.key -out debug.siguoya.name.crt
keepalive_timeout 100; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on;
若是咱們不想讓用戶經過HTTP來訪問,則能夠經過以下配置來強制HTTP訪問爲HTTPS訪問瀏覽器
server { listen 80; server_name debug.siguoya.name; location / { return 301 https://debug.siguoya.name$request_uri; } }
##查看證書列表 openssl crl2pkcs7 -nocrl -certfile /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem | openssl pkcs7 -print_certs -text -noout #查看證書Common Name列表 openssl crl2pkcs7 -nocrl -certfile /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem | openssl pkcs7 -print_certs -text -noout | grep 'CN=' | grep 'Subject'