为了提高web应用的安全性,现在基本上都需要支持https访问。在此记录一下自己在nginx下的配置过程

  • 安装Nginx这里就省略了
  • 安装openssl模块
yum -y install openssl

开始生成证书

# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..................................................................++++++
......................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key: # ls
~ server.key # cat server.key
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,D3E1935BAB9B90AB
8GVO2uvJf8MhMqZYlukRqbH01FDigvYqf6SNWf/TR7FZH9RkyNSezO7B9bqiL+te
3b2/ofW9xGiXDDAU4Cr7Wmg83f8vP4x9bZ19qzw0dU5PfD7IUnvVco7uwkPem8pn # openssl req -new -key server.key -out server.csr
Enter pass phrase for server.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) []:`BeiJing`
Locality Name (eg, city) [Default City]:`beijing`
Organization Name (eg, company) [Default Company Ltd]:`kingsoft`
Organizational Unit Name (eg, section) []:`kingsoft`
Common Name (eg, your name or your server's hostname) []:`vm-01`
Email Address []:`gaohongyu@kingsoft.com` Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:`12345678`
An optional company name []:`回车` # ls
~ server.csr server.key # cat server.csr
-----BEGIN CERTIFICATE REQUEST-----
MIICADCCAWkCAQAwgY4xCzAJBgNVBAYTAkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAw
DgYDVQQHDAdiZWlqaW5nMREwDwYDVQQKDAhraW5nc29mdDERMA8GA1UECwwIa2lu
Z3NvZnQxDjAMBgNVBAMMBXZtLTAxMSUwIwYJKoZIhvcNAQkBFhZnYW9ob25neXVA
a2luZ3NvZnQuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCic/v6n5yd
8fZE1ibpfH0ZrtesEE8iwp008sGYQh3Zr4t23/jZWs1vScv79Pz09uXGW3Bq7HaX
CdNMMun7hf2S5LCQhSCb+9d1mZMQ+EF17NYkm+mI/+hoT48x9TIOcOMMvUTB/gxx
Idmh0ah1ZUDEQJC3oqokmApvrycA23FKFwIDAQABoDEwFgYJKoZIhvcNAQkHMQkM
BzEzMTQyNTgwFwYJKoZIhvcNAQkCMQoMCGtpbmdzb2Z0MA0GCSqGSIb3DQEBCwUA
A4GBAHtJ3qTe5cpqiSJVi8nJqBvumrAJJSVvlE8/0FnP+cmrUUvWFpHnJ2KWDu5J
XqZynUjBjw8nXsxs62s+Z2DuMqWByRhVODABX6o/DoQ/5AMHY0prmwn1CgQOINeQ
WTXKsVFFuK3nVWUp53RheOcl1mN864K5gq7lBxVuV+3U8/88
-----END CERTIFICATE REQUEST----- # cp server.key server.key.org # openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key # openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=beijing/O=kingsoft/OU=kingsoft/CN=vm-01/emailAddress=gaohongyu@kingsoft.com
Getting Private key

Nginx配置https

vim nginx.conf 新增server节点,配置如下:
server {
server_name localhost;
listen 443 ssl;
ssl on;
ssl_certificate /usr/local/nginx/conf/crt/server.crt;
ssl_certificate_key /usr/local/nginx/conf/crt/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
ssl_prefer_server_ciphers on; }

重启nginx验证:nginx -s reload

打开浏览器验证:https://IP/index.html

Nginx支持https访问的更多相关文章

  1. nginx 支持https访问

    1,先确认nginx安装时已编译http_ssl模块. 就是执行nginx -V命令查看是否存在--with-http_ssl_module.如果没有,则需要重新编译nginx将该模块加入.yum安装 ...

  2. 配置nginx支持Https

    配置nginx支持Https一定要先使用stop停止nginx然后重新代开不能使用reload 一:安装letsencrypt 1.从git上克隆下来git clone https://github. ...

  3. 安装配置ingress-nginx支持https访问

    说明: ​ 1.k8s版本:v1.23: ​ 2.内网测试环境1台master,2台node节点,使用 DaemonSet+HostNetwork+nodeSelector 方式部署 ingress- ...

  4. 微信小程序如何提交审核并发布?发布问题:小程序只支持https访问

    http://www.jisuapp.cn/news/305.html 发布问题:1.小程序只支持https访问 2.要配置服务域名

  5. libcurl 不支持https访问

    项目中使用libcurl 访问https的时候会报错,比如:“Unsupported protocol” 或者:“Protocol https not supported or disabled in ...

  6. nginx使用ssl模块配置支持HTTPS访问

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译nginx时指定–with-http_ssl_module参数. 需求: 做一个网站域名为 www.localhost.cn 要求通过htt ...

  7. nginx使用ssl模块配置支持HTTPS访问【解决ssl错误】

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译nginx时指定–with-http_ssl_module参数. 需求:做一个网站域名为 www.localhost.cn 要求通过http ...

  8. nginx使用ssl模块配置支持HTTPS访问,腾讯云申请免费证书

    开始我尝试用 let's encrypt 让http 变 https 官方:https://github.com/certbot/certbot 参考:https://www.cnblogs.com/ ...

  9. nginx配置https访问

    一.准备 环境:centos6.8 nginx:1.13.6 二.开始       首先安装依赖包: yum install -y gcc gcc-c++ autoconf automake make ...

  10. windows下搭建nginx服务器及实现nginx支持https配置流程

    最近刚接触到了tomcat结合nginx做网站的负载均衡.之前对tomcat搭配nginx实现负载均衡也写过,在上一篇的博客中,最近遇到的问题是要在http的基础上支持https.也就是支持加密的请求 ...

随机推荐

  1. Win32封装对话框类

    [主程序入口.cpp] #include <windows.h> #include <tchar.h> #include "resource.h" #inc ...

  2. 去除WinForm程序中的Devexpress弹窗

    去除WinForm程序中的Devexpress弹窗 /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static ...

  3. 英文短句“xxx for the rest of us”的意思

    "xxx for the rest of us" 这个短语通常被理解为"为我们所有人"或"为我们剩下的人".为了更好地理解这个短语的意义,我 ...

  4. man 切换颜色配置

    man 命令显示的命令手册默认是没有颜色的.为了使 man 命令的输出更为生动,可以使用如下两种方法修改 man 命令的颜色配置. 方法一:设置环境变量 在你的 .zshrc / .bashrc 中添 ...

  5. python 或者 pyspark 和 java 交互, pyspark 里怎么调用自定义的 jar 包

    1. python 直接访问 jar 里面的类 先定义java文件,然后要访问java class, 需要有gateway server 和 entrypoint, 到时候python就可以连接上ga ...

  6. hexo使用小技巧

    1.在博客中加入图片 使用语法 {% asset_img 1.jpg %} 这样hexo会自动渲染1.jpg.,然后1.jpg的位置需要放在同文件名的文件夹中,比如这篇博客叫hexo使用小技巧,那么这 ...

  7. MyBatis——案例——环境准备

    配置文件完成增删改查      准备环境     数据库表 tb_brand        -- 创建tb_brand表 create table tb_brand( id int primary k ...

  8. Windows系统无法打开‘’网络发现‘’功能

    Windows10无法开启网络发现 解决办法: 1. services.msc 2. 开启 SSDP Discovery ,设置 启动类型为 自动 ,服务状态为 启动 Windows7 无法开启网络发 ...

  9. 【赵渝强老师】在Hive中使用Load语句加载数据

    一.Hive中load语句的语法说明 Hive Load语句不会在加载数据的时候做任何转换工作,而是纯粹的把数据文件复制/移动到Hive表对应的地址.语法格式如下: LOAD DATA [LOCAL] ...

  10. 【赵渝强老师】大数据分析引擎:Presto

    一.什么是Presto? 背景知识:Hive的缺点和Presto的背景 Hive使用MapReduce作为底层计算框架,是专为批处理设计的.但随着数据越来越多,使用Hive进行一个简单的数据查询可能要 ...