1、首先查看是否已经安装SSL

 openssl version -a

2、生成SSL证书

  1. nginx目录下创建ssl文件夹
  2. cd /etc/pki
  3. mkdir nginx
  4. cd nginx
  5. 生成2048位的加密私钥
  6. openssl genrsa -out server.key 2048
  7. 生成证书签名请求(CSR),这里需要填写许多信息
  8. openssl req -new -key server.key -out server.csr
  9. 输出内容为:
  10. Enter pass phrase for root.key: 输入前面创建的密码
  11. Country Name (2 letter code) [AU]:CN 国家代号,中国输入CN
  12. State or Province Name (full name) [Some-State]:BeiJing 省的全名,拼音
  13. Locality Name (eg, city) []:BeiJing 市的全名,拼音
  14. Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. 公司英文名
  15. Organizational Unit Name (eg, section) []: 可以不输入
  16. Common Name (eg, YOUR name) []: 服务器主机名,若填写不正确,浏览器会报告证书无效,但并
  17. Email Address []:admin@mycompany.com 电子邮箱,可随意填
  18. Please enter the following extra attributes
  19. to be sent with your certificate request
  20. A challenge password []: 可以不输入
  21. An optional company name []: 可以不输入
    生成类型为X509的自签名证书。有效期设置3650天,即有效期为10
    openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

  

3、修改Nginx配置文件

  1. # For more information on configuration, see:
  2. # * Official English Documentation: http://nginx.org/en/docs/
  3. # * Official Russian Documentation: http://nginx.org/ru/docs/
  4.  
  5. user nginx;
  6. worker_processes auto;
  7. error_log /var/log/nginx/error.log;
  8. pid /run/nginx.pid;
  9.  
  10. # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
  11. include /usr/share/nginx/modules/*.conf;
  12.  
  13. events {
  14. worker_connections 1024;
  15. }
  16.  
  17. http {
  18. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. '$status $body_bytes_sent "$http_referer" '
  20. '"$http_user_agent" "$http_x_forwarded_for"';
  21.  
  22. access_log /var/log/nginx/access.log main;
  23.  
  24. sendfile on;
  25. tcp_nopush on;
  26. tcp_nodelay on;
  27. keepalive_timeout 65;
  28. types_hash_max_size 2048;
  29.  
  30. include /etc/nginx/mime.types;
  31. default_type application/octet-stream;
  32.  
  33. # Load modular configuration files from the /etc/nginx/conf.d directory.
  34. # See http://nginx.org/en/docs/ngx_core_module.html#include
  35. # for more information.
  36. include /etc/nginx/conf.d/*.conf;
  37.  
  38. server {
  39. listen 80 default_server;
  40. listen [::]:80 default_server;
  41. server_name _;
  42. root /usr/share/nginx/html;
  43.  
  44. # Load configuration files for the default server block.
  45. include /etc/nginx/default.d/*.conf;
  46.  
  47. location / {
  48.  
  49. }
  50.  
  51. error_page 404 /404.html;
  52. location = /40x.html {
  53. }
  54.  
  55. error_page 500 502 503 504 /50x.html;
  56. location = /50x.html {
  57. }
  58. }
  59.  
  60. # Settings for a TLS enabled server.
  61. #
  62. server {
  63. listen 443 ssl http2 default_server;
  64. listen [::]:443 ssl http2 default_server;
  65. server_name _;
  66. root /usr/share/nginx/html;
  67.  
  68. ssl_certificate "/etc/pki/nginx/server.crt"; #生成的自签名文件
  69. ssl_certificate_key "/etc/pki/nginx/server.key"; #生成的私钥文件
  70. ssl_session_cache shared:SSL:1m;
  71. ssl_session_timeout 10m;
  72. ssl_ciphers HIGH:!aNULL:!MD5;
  73. ssl_prefer_server_ciphers on;
  74.  
  75. # Load configuration files for the default server block.
  76. include /etc/nginx/default.d/*.conf;
  77.  
  78. location / {
  79. }
  80.  
  81. error_page 404 /404.html;
  82. location = /40x.html {
  83. }
  84.  
  85. error_page 500 502 503 504 /50x.html;
  86. location = /50x.html {
  87. }
  88. }
  89.  
  90. }

 检查配置文件是否正确

  1. nginx -t

重启服务

  1. service nginx reload

 

开启Nginx代理HTTPS功能的更多相关文章

  1. nginx代理https站点(亲测)

    nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...

  2. Nginx代理缓存功能

    Nginx代理缓存功能      Nginx缓存主要是用于减轻后端服务器的负载,提高网站并发量,提升用户体验度. 注意:Nginx反向代理的缓存功能是由ngx_http_proxy_module提供, ...

  3. nginx 代理 https 后,应用变成 http

    需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...

  4. nginx 代理https后,应用redirect https变成http --转

    原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...

  5. nginx使用https功能

    nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/n ...

  6. Nginx 高级配置-https 功能

    Nginx 高级配置-https 功能 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HTTPS工作过程 1>.SSL/TLS SSL(Secure Socket Lay ...

  7. Nginx代理前端代码

    Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...

  8. 关于配置websocket,nginx转发https至wss问题

    在本地测试通过的socket,再放到现在的有nginx代理之后发现会报:failed: Error in connection establishment: net::ERR_NAME_NOT_RES ...

  9. nginx的https和http共存反向代理配置

    一.设置http反向代理: upstream ly.com { server ; server ; } upstream home.ly.com { server ; server ; } 对应增加: ...

随机推荐

  1. Android开发,缺少权限导致无法修改原文件,获取所有文件访问权限的方法

    在Android 11开发中,app会遇到使用绝对路径无法打开某文件的情况(文件存在根目录下,获取到的路径为:/storage/emulated/0/XXX.txt),而使用相对路径打开文件后(获取到 ...

  2. VS Code闪现,巨头纷纷入局的Web IDE缘何崛起?

    我发了,我装的. 就在前几天,微软简短的发布了Visual Studio Code for the Web 的公告,而没过一阵,这则公告就被删除了,现在点经相关内容已经是404状态了.虽然公告的内容已 ...

  3. RabbitMQ之消息模式1

    消息100%的投递 消息如何保障100%的投递成功? 什么是生产端的可靠性投递? 保障消息的成功发出 保障MQ节点的成功接收 发送端收到MQ节点(Broker)确认应答 完善的消息进行补偿机制 BAT ...

  4. 即时通讯网-TCPIP族关系图

  5. js实现钟表

    在网页上显示一个钟表 html: <body onload="startTime()"> <div id="txt"></div& ...

  6. LVS负载均衡集群--DR模式部署

    目录: 一.LVS-DR数据包流向分析 二.DR 模式的特点 三.LVS-DR中的ARP问题 四.DR模式 LVS负载均衡群集部署 一.LVS-DR数据包流向分析 1.为方便进行原理分析,将clien ...

  7. 1.docker概述及其历史

    一. 为什么会出现docker? 不用说, 肯定是时代进步的产物. 那么, 他为什么能火? 一定是解决了痛点问题. docker也不是一下子就火起来了, 他的火也是有一个过程的, 我们先来看看为什么会 ...

  8. 基于python2.7 Tkinter 做一个小工具

    1.源码:先写一个界面出来,放需要放入的点击事件的函数 # -*- coding:utf-8 -*- import Tkinter from Tkinter import * import Excle ...

  9. C# 动态构建表达式树(一)—— 构建 Where 的 Lambda 表达式

    C# 动态构建表达式树(一)-- 构建 Where 的 Lambda 表达式 前言 记得之前同事在做筛选功能的时候提出过一个问题:如果用户传入的条件数量不确定,条件的内容也不确定(大于.小于和等于), ...

  10. Java Web下MySQL数据库的增删改查(一)

    以图书管理系统举例(jsp+servlet+bean) 1.数据库的连接 package db; import java.sql.Connection; import java.sql.DriverM ...