基于nginx结合openssl实现https

[root@localhost ~]#systemctl stop firewalld

 

[root@localhost ~]#setenforce 0

[root@localhost ~]#iptables -F

[root@localhost ~]#yum -y install pcre zlib openssl openssl-devel pcre-devel zlib-devel

[root@localhost ~]#cd /usr/local/nginx-1.16.0

[root@localhost nginx-1.16.0]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module

[root@localhost ~]#make && make install

[root@localhost ~]#useradd -M -s /sbin/nologin nginx

[root@localhost ~]#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin

[root@localhost ~]#nginx

[root@localhost ~]# touch /etc/pki/CA/index.txt

[root@localhost ~]# echo 01 > /etc/pki/CA/serial

[root@localhost ~]# cd /etc/pki/CA/

[root@localhost CA]# umask 066

[root@localhost CA]# openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048

[root@localhost ~]# openssl req -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:WXYC
Organizational Unit Name (eg, section) []:JSB
Common Name (eg, your name or your server's hostname) []:wangfeiyu.com
Email Address []:wangfeiyu@sina.com     

 

[root@localhost ~]#  cd

[root@localhost ~]# mkdir key
[root@localhost ~]# cd key/
[root@localhost key]# umask 066
[root@localhost key]# openssl genrsa -out service.key 2048
[root@localhost key]# openssl req -new -key service.key -out service.csr
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:WXYC
Organizational Unit Name (eg, section) []:JSB
Common Name (eg, your name or your server's hostname) []:wangfeiyu.com
Email Address []:wangfeiyu@sina.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:   

 

###建议不设置密码

[root@localhost key]# mkdir /etc/pki/CA/csr
[root@localhost key]# mv service.csr /etc/pki/CA/csr
[root@localhost key]# openssl ca -in /etc/pki/CA/csr/service.csr -out /etc/pki/CA/certs/service.crt -days 365
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y

修改nginx配置文件添加

server {
listen 443 ssl;
server_name nginx.nihao.com;

ssl_certificate /etc/pki/CA/cacert.pem;
ssl_certificate_key /etc/pki/CA/private/cakey.pem;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}

重启nginx服务

修改主机hosts文件    192.168.200.111  nginx.wangfeiyu.com

 

 成功

 

转载于:https://www.cnblogs.com/maoyanqing/p/11529934.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值