打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
nginx 配置https

nginx 配置https

同事测试一ssl加密接口,但是负责该接口的同事有事请假了没在,所以我就临时给配置了一个https服务,写了一个简单接口供同事使用,配置nginx的https记录一下:

一、生成私钥和证书

创建带密钥口令的私钥
root@mysqlmaster:/tmp# openssl genrsa -des3 -out ng.key 1024
Generating RSA private key, 1024 bit long modulus
........++++++
...........................................++++++
e is 65537 (0x10001)
Enter pass phrase for ng.key: 输入口令
Verifying - Enter pass phrase for ng.key: 确认口令
二、创建csr文件
root@mysqlmaster:/tmp# openssl req -new -key ng.key -out ng.csr
Enter pass phrase for ng.key:
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,hk
State or Province Name (full name) [Some-State]:州或省的名称 如Beijing
Locality Name (eg, city) []:什么地方级别,是城市还是乡镇
Organization Name (eg, company) [Internet Widgits Pty Ltd]:什么组织,如公司,政府
Organizational Unit Name (eg, section) []:组织单位名称
Common Name (eg, YOUR name) []:名字
Email Address []:邮件地址

Please enter the following 'extra' attributes 额外信息
to be sent with your certificate request
A challenge password []: 复杂密码
An optional company name []:

1,创建私钥(去除密钥口令)
openssl rsa -in ng.key -out server.key
输入口令

2,创建CA证书
openssl req -new -x509 -days 3650 -key server.key -out server.crt
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]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:
和上面的步骤差不多,根据提示输入证书的信息,国家,管理人邮件,姓名,城市等


三、修改nginx配置文件

root@mysqlmaster:/tmp# cp server.crt server.key /etc/nginx/
默认需要证书放到nginx/conf/目录,那么
vi /etc/nginx/nginx.conf

增加

server{
listen 443;
server_name localhost;
ssl on;
ssl_certificate server.crt; #证书
ssl_certificate_key server.key; #私钥
location / {
root html;
index index.html index.htm;
}
}
root@mysqlmaster:/tmp# service nginx restart
重启服务
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
nginx上配置正式的https证书
Linux下nginx配置https协议访问的方法
linux 下生成ssl自签证书并配置nginx通过https访问(好使)
使用openssl生成证书,并通过Nginx配置
Nginx HTTPS功能部署实践
HTTPS服务器配置(转)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服