实现Nginx https

Nginx要实现SSL认证需要在编译时启用--with-http_ssl_module模块,并且nginx支持一台服务器上实现多虚拟主机的https

1.使用nginx -V查看nginx在编译时是否启用了ssl_module模块

[root@localhost ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

2.在nginx目录下创建存放证书的目录

[root@localhost ~]# mkdir /apps/nginx/certs
[root@localhost ~]# cd /apps/nginx/certs

3.生成CA自签证书及CA的私钥

[root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 3650 -out ca.crt
Generating a 4096 bit RSA private key
....................++
...........................................................................................................................................................................++
writing new private key to 'ca.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) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:magedu.com
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:ca.magedu.com
Email Address []:438214186@qq.com

4.生成私钥及证书签署请求

[root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout www.mylinuxops.com.key -out www.mylinuxops.com.csr
Generating a 4096 bit RSA private key
.......................................................................................++
.............................................................................................................................................................................................++
writing new private key to 'www.mylinuxops.com.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) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:magedu.com
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www.mylinuxops.com
Email Address []:438214186@qq.comPlease enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

5.签发证书

[root@localhost certs]# openssl x509 -req -days 3650 -in www.mylinuxops.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out www.mylinuxops.com.crt
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=magedu.com/OU=ops/CN=www.mylinuxops.com/emailAddress=438214186@qq.com
Getting CA Private Key

6.查看签发的证书

[root@localhost certs]# openssl x509 -in www.mylinuxops.com.crt -noout -text
Certificate:Data:Version: 1 (0x0)Serial Number:b9:a1:a3:24:b8:03:cc:86Signature Algorithm: sha256WithRSAEncryptionIssuer: C=CN, ST=BJ, L=BJ, O=magedu.com, OU=ops, CN=ca.magedu.com/emailAddress=438214186@qq.comValidityNot Before: May 29 12:06:50 2019 GMTNot After : May 26 12:06:50 2029 GMTSubject: C=CN, ST=BJ, L=BJ, O=magedu.com, OU=ops, CN=www.mylinuxops.com/emailAddress=438214186@qq.comSubject Public Key Info:Public Key Algorithm: rsaEncryptionPublic-Key: (4096 bit)Modulus:00:e9:2c:9b:56:63:b7:64:e0:37:f4:07:8e:0e:e2:4b:6f:47:c4:e3:25:5d:2d:b6:64:e6:0e:36:fa:de:81:0a:83:e8:61:f2:8b:e4:a0:2f:21:b4:db:6f:94:e7:5c:b9:d9:6b:ca:3d:d0:6e:f5:a2:6c:a7:2f:38:2f:60:d1:ca:07:55:90:6b:18:75:e2:51:9c:7b:5c:79:30:50:e3:01:e0:93:c5:ee:06:79:51:9b:18:c7:ba:ed:4f:30:2d:aa:a8:15:3c:1c:02:23:c7:1e:c5:68:69:7c:69:9c:08:ef:9c:69:6e:8b:6d:d7:1f:5b:64:45:6a:37:03:4a:1e:10:fb:36:24:6a:ce:3f:48:4b:46:5c:39:d6:14:79:5d:c4:c8:8f:d1:9d:e5:68:23:e3:79:18:44:2a:20:71:5b:02:27:a3:17:20:47:aa:8c:42:b6:00:d9:2e:45:65:a4:e9:2e:cf:d1:a8:72:7d:3d:4a:d9:f8:78:44:3b:ae:0c:6d:f6:e5:da:7f:10:45:4a:09:b3:b3:ba:cb:f7:c6:ab:31:cb:8c:4d:d6:db:13:49:cc:f5:a9:78:3d:7d:67:b9:03:09:f8:6d:b2:87:13:5d:61:d8:c3:a5:fa:97:2d:27:e2:4a:53:89:4c:c2:11:05:03:6f:5a:ff:ed:35:43:44:98:0b:a8:0b:ba:71:64:d7:f1:59:0e:4d:e3:ca:77:7c:66:91:4e:9d:e7:53:82:12:99:31:ba:78:85:d8:39:03:14:1c:46:70:5c:24:3e:f0:0a:65:30:da:03:eb:70:76:8a:70:b6:9a:9c:cb:e9:b3:4d:b3:3b:bc:e6:cd:7d:5a:5c:61:d1:f5:47:80:be:c5:c3:f1:08:6e:79:56:06:57:8a:67:e5:e8:af:eb:b0:ba:f5:54:18:6d:ce:df:28:a5:b0:18:18:9f:91:ad:e7:d1:c4:f3:35:d1:54:7f:a2:48:1b:62:a1:59:50:1b:6f:2e:3e:9b:38:f9:99:85:b3:91:b0:87:ce:88:13:2a:fc:d9:1d:6c:9d:38:f0:97:53:c0:9d:46:a1:e7:a8:08:2f:d4:90:8b:3a:9b:a4:22:4a:31:23:0d:13:b9:97:29:37:df:47:e9:06:95:e5:25:13:90:aa:a1:c6:11:64:fd:49:84:0a:81:15:8d:fb:ef:29:28:b2:6b:b0:82:a4:d1:8c:f4:cd:7a:88:3b:14:77:b2:55:f0:e3:4f:a6:3a:11:4b:3b:26:9e:a2:e6:b9:a1:dc:07:c6:da:01:d3:63:88:1b:05:c7:88:b7:5b:13:1b:83:31:7c:0e:e7:09:11:f3:a5:b5:26:20:2c:34:f6:21:ac:af:ab:97Exponent: 65537 (0x10001)Signature Algorithm: sha256WithRSAEncryptiona2:42:b5:26:40:63:2c:6f:c8:58:0f:ae:59:05:31:96:10:c5:9e:26:78:74:d5:21:75:82:8d:3b:ad:71:ab:94:78:ce:d3:45:0d:ad:e1:9d:1f:b7:e6:de:f0:2b:e6:2d:7e:fe:3b:0c:f2:5a:85:7c:3b:f4:01:2c:e8:cd:71:b4:e0:e1:8a:cf:e5:90:c3:93:6d:2d:22:fb:f8:79:24:a6:f8:ed:ed:1c:97:db:52:31:69:74:3c:c1:00:45:1e:74:f0:93:3d:f6:15:82:39:3b:4c:6c:bb:72:4b:66:fd:6d:10:56:a1:86:a0:11:02:2a:c4:de:80:fd:93:d6:5f:c2:18:b7:1a:f3:89:4e:dc:18:b8:fc:70:eb:94:51:91:fc:f7:7a:1b:cf:36:fa:52:c9:1a:95:e6:ec:bb:1a:ef:7d:dc:67:62:dc:95:13:76:7e:a3:17:3f:c6:cb:82:a6:bb:89:69:98:1c:3e:78:e8:94:50:71:7f:be:66:94:7d:de:bb:02:1a:57:ad:f2:56:bc:61:a1:7d:c0:1c:f7:df:1b:75:7f:d0:0c:19:46:a8:d6:37:e4:b6:a7:0e:12:2a:04:a6:ad:ee:ec:ae:7f:49:bf:bb:a7:d7:3c:71:eb:e6:d0:97:f8:4b:22:29:34:11:3c:86:e9:e7:51:35:92:0b:4a:3b:d6:39:db:54:50:bf:d2:f2:ed:da:ca:e8:e7:55:b9:36:c9:29:13:83:51:2c:de:5d:df:da:53:58:47:64:5b:92:1c:44:ec:61:7d:d5:b4:77:04:16:3e:24:5b:48:60:df:63:a3:36:57:a0:e1:f1:39:e4:bc:f5:81:53:7e:50:a3:b8:85:32:d8:58:60:4e:bb:ee:24:ee:d9:74:62:c3:e0:c8:80:5a:58:af:09:6d:73:b4:05:f2:0d:2c:04:47:a0:0b:3e:75:2e:13:a5:e1:f2:1f:06:ad:88:36:70:03:5b:c4:38:94:22:da:0e:56:c2:f5:6d:31:4c:ef:9e:05:2e:85:87:fa:2b:21:76:fc:c4:f9:13:d4:1c:c4:1a:31:95:b9:5d:ee:38:31:de:3d:35:00:76:9d:d8:45:e1:97:c0:10:07:5e:1c:5c:ad:85:51:37:8e:11:93:6d:69:cd:b4:70:8b:45:1d:c3:57:61:d0:8b:ea:f8:2c:91:9c:22:71:00:70:02:e3:4b:3e:19:1f:67:1d:9c:9f:e2:ae:64:1b:53:6c:be:5e:15:5e:de:15:36:e2:55:37:07:8f:c9:62:06:ce:d9:5a:99:99:cb:bc:a4:fc:88:7e:cf:45:91:f1:1f:20:e4:eb:a7:0f:b9:8f:0e:5a:25:71:5f:d1:1a

7.修改配置文件启用ssl

server {server_name www.mylinuxops.com;listen 443;ssl on;ssl_certificate /apps/nginx/certs/www.mylinuxops.com.crt;       #添加证书文件ssl_certificate_key /apps/nginx/certs/www.mylinuxops.com.key;   #添加私钥文件ssl_session_timeout 10m;        #设置ssl会话的超时时间ssl_session_cache shared:SSL:20m;        #设置ssl会话的缓存大小,shared为共享缓存,可以给多个worker进程使用,需要设置缓存名字,还需要设置大小,官方1M可以存储4000个会话location / {root /data/www;index index.html;}
}

8.检查配置文件,重读配置文件

[root@localhost nginx]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# nginx -s reload

9.测试

[root@localhost nginx]# curl --cacert /apps/nginx/certs/ca.crt  https://www.mylinuxops.com
mylinux.com

转载于:https://blog.51cto.com/11886307/2403938

实现Nginx https相关推荐

  1. Angular Web App部署Linux Nginx Https

    Angular Web App部署Linux Nginx Https 提示:这篇文章是基于内网的 互联网就开始将 WEB 服务从 HTTP 迁移到 HTTPS,而现在为了更快的推进 HTTPS 的普及 ...

  2. Nginx学习总结(6)——Nginx + https + 免费SSL证书配置指南

    操作环境 操作系统:centos5.5 前段静态内容处理:nginx 后端JSP处理:tomcat 6 一.Nginx + https + 免费SSL证书配置指南 生成证书 $ cd /usr/loc ...

  3. 11. Nginx HTTPS

    Nginx HTTPS HTTPS基本概念 1.SSL 安全套接层 认证用户和服务器,确保数据发送到正确的客户机和服务器 加密数据以防止数据中途窃取 维护数据的完整性,确保数据在传过程中不被改变 2. ...

  4. linux:Nginx+https双向验证(数字安全证书)

    本文由邓亚运提供 Nginx+https双向验证 说明: 要想实现nginx的https,nginx必须启用http_ssl模块:在编译时加上--with-http_ssl_module参数就ok.另 ...

  5. Nginx https 协议配置 ssl_protocols 的相关问题

    1. Nginx https相关配置 官方说明:详细看这里 本文主要针对以下两个主要配置从代码层次进行分析: 协议配置: Syntax: ssl_protocols [SSLv2] [SSLv3] [ ...

  6. 优化 Nginx HTTPS 延迟 - 看我如何让Nginx提速 30%的?

    点击上方关注 "终端研发部" 设为"星标",和你一起掌握更多数据库知识 为什么要优化 Ngin HTTPS 延迟 Nginx 常作为最常见的服务器,常被用作负载 ...

  7. 高性能 Nginx HTTPS 调优 - 如何为 HTTPS 提速 30%

    开发者(KaiFaX) 面向全栈工程师的开发者专注于前端.Java/Python/Go/PHP的技术社区 来源: https://kalasearch.cn/blog/high-performance ...

  8. nginx配置http、https访问,nginx指定ssl证书,阿里云腾讯云华为云设置nginx https安全访问

    nginx配置http.https访问 要设置https访问需要从对应的云厂商申请证书,并下载Nginx证书到服务器. 我这里从阿里云申请了免费的域名证书,然后将证书放置在服务器的/etc/ssl/. ...

  9. Ubuntu下配置Nginx HTTPS

    HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即HTTP下加入S ...

最新文章

  1. Elasticsearch 知识点目录
  2. 创建守护进程关键步骤
  3. 天转凉了,注意保暖,好吗(需求规格说明书放在github了)
  4. asp.net 分布式应用开发
  5. 《疯狂前端开发讲义jQuery+Angular+Bootstrap前端开发实践》学习笔记
  6. 面试容易问的 JavaScript 知识点,你知道几个?
  7. android 带边框的arc,极细边框(1px边框)实现方式
  8. QQ查看撤回的语音消息,slk 文件转 mp3
  9. 自己动手开发编译器(三)有穷自动机
  10. 黎曼 zeta 函数与黎曼猜想
  11. [财务][数据化分析][财务背景知识][财务三张基础表][资产负债表][利润表][现金流量表]看懂财务三张表,以后看表再也不求人了...
  12. 计算机双工模式,小熊教你电脑设置连接速度和双工模式
  13. Html5 Egret游戏开发 成语大挑战(三)开始界面
  14. 解决 hsdb jinfo jmap sa-jdi等mac不可用问题
  15. 今日头条校园招聘历年经典面试题汇总:C++研发岗
  16. 一位年薪35W的测试被开除,回怼的一番话,令人沉思
  17. 纺织服装行业数字化供应商协同平台:优化企业供应网络,轻松选择优质供应商
  18. 赵小楼《天道》《遥远的救世主》深度解析(95)人、性、佛性、智慧的有迹可循
  19. 基于ssm美食推荐管理系统获取(java毕业设计)
  20. fis3项目个人理解

热门文章

  1. html5+调用safari,Safari浏览器不酷,HTML5无效元素; JavaScript是
  2. java path设置错误_linux下环境变量PATH设置错误的补救
  3. Premiere Pro CC2019安装资料及安装教程
  4. python list去掉引号_最新的python面试题集170之三(基础性学习)
  5. 面试中Spring常见问题
  6. 域控制器安装完成没有_tcp_udp_Windows 安装 Jupyter Lab
  7. motan yar php,motan学习笔记 六 opentracing Brave+zipkin实现-Go语言中文社区
  8. python0.1+0.2不等于0.3_为什么0.1 + 0.2不等于0.3?
  9. Docker的镜像使用
  10. java bat 运行 jar文件_运行bat文件启动java的jar且不弹出DOS窗口,后台运行java的jar包...