1. openssl的版本信息

[root@localhost conf]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013

2. openresty的版本信息

[root@localhost sbin]# ./nginx -V

3. 创建服务器私钥,命令会提醒输入一个密码,必须输入(在nginx的conf所在的路径下进行操作,当然也可以在其他路径,需要配合后续的nginx的配置一起改变

[root@localhost conf]# openssl genrsa -des3 -out server.key
Generating RSA private key, bit long modulus
..............................................................++
........................++
e is (0x10001)
Enter pass phrase for server.key:
:error::lib():UI_set_result:result too small:ui_lib.c::You must type in to characters
Enter pass phrase for server.key:
:error::lib():UI_set_result:result too small:ui_lib.c::You must type in to characters
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
[root@localhost conf]# ll
总用量
-rw-r--r--. root root 3月 : fastcgi.conf
-rw-r--r--. root root 3月 : fastcgi.conf.default
-rw-r--r--. root root 3月 : fastcgi_params
-rw-r--r--. root root 3月 : fastcgi_params.default
-rw-r--r--. root root 3月 : koi-utf
-rw-r--r--. root root 3月 : koi-win
-rw-r--r--. root root 3月 : mime.types
-rw-r--r--. root root 3月 : mime.types.default
-rw-r--r--. root root 3月 : nginx.conf
-rw-r--r--. root root 3月 : nginx.conf.default
-rw-r--r--. root root 3月 : scgi_params
-rw-r--r--. root root 3月 : scgi_params.default
-rw-r--r-- root root 7月 : server.key
-rw-r--r--. root root 3月 : uwsgi_params
-rw-r--r--. root root 3月 : uwsgi_params.default
-rw-r--r--. root root 3月 : win-utf

4. 创建签名请求的证书(CSR)

[root@localhost conf]# 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 ( letter code) [XX]:cn
State or Province Name (full name) []:hubei
Locality Name (eg, city) [Default City]:wuhan
Organization Name (eg, company) [Default Company Ltd]:tk
Organizational Unit Name (eg, section) []:iflab
Common Name (eg, your name or your server's hostname) []:root
Email Address []:shihuc@.com Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:shihuc
An optional company name []:tk
[root@localhost conf]#

5. 在加载SSL支持的Nginx服务器上,使用上述私钥时除去必须的口令(注意,所谓除去,其实就是将必须的私钥密码写入到了私钥文件里面了,更新了原来的私钥文件)

[root@localhost conf]# cp server.key server.key.org
[root@localhost conf]#
[root@localhost conf]# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key
[root@localhost conf]#

6. 通过openssl的x509指令生产证书文件

[root@localhost conf]# openssl x509 -req -days  -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=cn/ST=hubei/L=wuhan/O=tk/OU=iflab/CN=root/emailAddress=shihuc@.com
Getting Private key

7. nginx的简单配置

# HTTPS server
#
server {
listen ssl;
server_name localhost; ssl_certificate server.crt;
ssl_certificate_key server.key; ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
root html/SSLROOT;
index index.html index.htm;
}
}

在nginx的html目录下,创建SSLROOT目录,并在下面创建一个index.html的页面,用于测试。

8. 一个用于转发的nginx.conf文件

worker_processes        ;
error_log logs/error.log;
events {
worker_connections ;
} http {
keepalive_timeout ;
sendfile on; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; server {
listen ssl;
# listen ssl;
server_name localhost; ssl_certificate kaili.axinfu.com.crt;
ssl_certificate_key kaili.axinfu.com.key; ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
root html/SSLROOT;
index index.html index.htm;
# 开启白名单,根据需求替换
allow 127.0.0.1;
allow 192.168.11.10;
deny all; #反向代理,根据需求替换
proxy_pass http://192.168.11.10:9581;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}

参考:https://www.cnblogs.com/shihuc/p/7150900.html

基于openresty配置https访问的更多相关文章

  1. Linux Apache配置https访问

    配置https访问 该环境是rh254课程配套的一个环境,不过配置方法步骤相同. 要求: 使用虚拟主机技术部署两个网站: 网站1: 绑定域名 www0.example.com 目录在 /srv/www ...

  2. OkHttp配置HTTPS访问+服务器部署

    1 概述 OkHttp配置HTTPS访问,核心为以下三个部分: sslSocketFactory() HostnameVerifier X509TrustManager 第一个是ssl套接字工厂,第二 ...

  3. 使用docker搭建最新版本的gitea,并配置HTTPS访问

    使用docker搭建最新版本的gitea,并配置HTTPS访问 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 简介 之前有搭建 ...

  4. 基于openresty的https配置实践

    最近机器人项目的子项目,由于和BAT中的一家进行合作,人家要求用HTTPS连接,于是乎,我们要改造我们的nginx的配置,加添HTTPS的支持. 当然了,HTTPS需要的证书,必须是认证机构颁发的,这 ...

  5. lamp之apache配置https访问

    配置apache 使用https 注:怕其他人由于路径的原因出问题,首先声明一下,本人apache的安装目录为 : /usr/local/httpd2.4.25,如果不是,请参考进行配置 注: 对于如 ...

  6. nginx配置https访问

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

  7. 本地测试Tomcat配置Https访问

    一.tomcat开启HTTPS配置 1) 准备证书 使用jdk工具keytool生成一个ssl测试用证书, 一路按照提示操作输入即可 keytool -genkey -alias tomcat -ke ...

  8. Apache 配置 HTTPS访问

    将需要配置的项目移动到另一根目录下,作为https访问位置. 修改bitnami配置文件..\Bitnami\wampstack-5.6.19-0\apache2\conf\bitnami\bitna ...

  9. 4-OpenResty 配置 https 访问

    首先是下载证书  https://www.cnblogs.com/yangfengwu/p/11809757.html 因为咱用的 Nginx 所以 修改这个 server { listen ssl; ...

随机推荐

  1. MonoBehaviour.OnValidate

    [MonoBehaviour.OnValidate] This function is called when the script is loaded or a value is changed i ...

  2. 41. First Missing Positive (HashTable)

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  3. centos7 ntp服务器配置

    一.ntp服务是什么 1. 定义 NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 2. 发展 首次记载在Internet Enginee ...

  4. Windows本地Linux虚拟机ping不通的解决办法

    解决办法:启动虚拟机双网卡支持: 网卡1:Host-Only网络 网卡2:NAT网络 设置好以后,可以在Linux主机中ifconfig查看本地Host-Only的网络地址,与电脑中的地址应该是同一网 ...

  5. 不同包之间的继承extends

    情景如下: 两个类:ExtendsSuper(父类).ExtendsSub(子类) 两个包:父类ExtendsSuper位于包packSuper路径下,子类ExtendsSub位于包packSub路径 ...

  6. nginx 负载均衡 使用ip_hash方式解决session问题 测试

    ip_hash的方式比较弱智,但是在一般情况下是挺有效的~~,如果能保证nginx是最上一层的代理,那么能够得到用户的ip是真实位置,就能做到负载,但是一家公司的所有员工其实走的是同一个ip,那么在这 ...

  7. Mac完整卸载Android Studio的方法

    1.卸载Android Studio,在终端(terminal)执行以下命令: rm -Rf /Applications/Android\ Studio.app rm -Rf ~/Library/Pr ...

  8. 【转】java遍历实体类的属性和数据类型以及属性值

    和同学接了个外包的活,由于项目中很多地方要用到poi导出excel,而每次导出都要写很多相同的代码,因为poi的cell.setCellValue();每次设置的都是不同实体bean的属性值,导致代码 ...

  9. Nginx学习基础(一)

    Nginx是个可靠高效的中间件,就是跟其他语言连接,可以做为一个工具的服务器. 可以处理的问题: 1.反向代理 (1)正向代理(以客户端为主):访问网站的时候,早起是在做通过n多个路由访问网站的操作, ...

  10. Oracle学习笔记(十)

    光标(游标)概念引入 就是一个结果集(查询或者其他操作返回的结果是多个时使用)定义一个光标 cursor c1 is select ename from emp: 从光标中取值 打开光标: --ope ...