nginx1.14.0版本https加密配置
修改host文件,为最后访问域名准备
C:\Windows\System32\drivers\etc host文件目录
192.168.10.140 www.joyce.com 在最后添加这个自定义域名
https公钥和私钥定义
服务端:公钥、私钥
服务器持有一对公钥和私钥,并且把自己的公钥发给客户端。
当浏览器发起申请时,数据通过浏览器端的私钥加密发送给服务端。服务端拿到加密密文时,通过浏览器的公钥解密得到数据。
服务端再通过自己的私钥加密返回数据到浏览器,浏览器拿到密文后通过服务端的公钥解密得到数据。
下载nginx和安装
cd /usr/local
wget http://nginx.org/download/nginx-1.14.0.tar.gz 下载
tar -zxvf nginx-1.14.0.tar.gz 解压
/usr/local/nginx/sbin/nginx -V 查看ngixn版本极其编译参数
cd nginx-1.14.0 进入nginx源码目录
./configure
#make & make install 编译和安装
要添加ssl加密模块,需重新编译模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
make 千万别make & make install,否则就覆盖安装了。make完之后在objs目录下就多了个nginx,这个就是新版本的程序了
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak 备份旧的nginx程序
rm -rf /usr/local/nginx/sbin/nginx 先删除旧的nginx程序
cp objs/nginx /usr/local/nginx/sbin/nginx 把新的nginx程序覆盖旧的
生成https crt证书文件
yum -y update 更新yum源
yum -y install openssl 安装ssl
cd /usr/local/nginx
mkdir ssl 创建ssl文件夹
cd ssl
openssl genrsa -des3 -out server.key 1024 生成server.key私钥文件,长度为1024,需要指定一个密码:123456
-out filename :将生成的私钥保存至filename文件,若未指定输出文件,则为标准输出。
-numbits :指定要生成的私钥的长度,默认为1024。该项必须为命令行的最后一项参数。
-des|-des3|-idea:指定加密私钥文件用的算法,这样每次使用私钥文件都将输入密码,太麻烦所以很少使用。
-passout args :加密私钥文件时,传递密码的格式,如果要加密私钥文件时单未指定该项,则提示输入密码。传递密码的args的格式见openssl密码格式。
openssl req -new -key server.key -out server.csr 生成server.csr公钥文件,需要输入server.key里指定的密码,我这里是:123456
[root@192 ssl]# 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]:cs
State or Province Name (full name) []:www.joyce.com
Locality Name (eg, city) [Default City]:ShangHai
Organization Name (eg, company) [Default Company Ltd]:joyce
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:joyce
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@192 ssl]#
以上这些后面带[]的都是选填,可以直接回车不填。
接下来去除私钥的口令验证,也就是去除用户名密码登录校验
cp server.key server.key.org 先复制一份
openssl rsa -in server.key.org -out server.key 去除口令后,覆盖server.key文件。需要输入server.key里指定的密码:123456
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 标记证书使用私钥和csr,使用x509格式,有效期限365天
[root@192 ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=cs/ST=www.joyce.com/L=ShangHai/O=joyce/CN=joyce
Getting Private key
注意!server.crt 就是我们需要的证书!
nginx.conf 配置https配置
vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name www.joyce.com;
return 301 https://$server_name$request_uri; 301重定向到https协议端口,这样访问http://www.joyce.com会自动跳转到https://www.joyce.com
# 可以参考:https://www.cnblogs.com/liuq1991/p/9019900.html (nginx http转 https)
}
server {
listen 443 ssl;
server_name www.joyce.com;
ssl on; 启用https协议访问
ssl_certificate /usr/local/nginx/ssl/server.crt; 服务端公钥
ssl_certificate_key /usr/local/nginx/ssl/server.key; 服务端私钥
error_log /usr/local/nginx/logs/error443.log;
location / {
proxy_pass http://192.168.10.140:8761; 访问应用
}
}
}
测试新的nginx.conf是否配置正确
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -t
输出如下结果代表nginx.conf配置文件无误:
nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful
平滑重启nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload
查看ngixn版本极其编译参数
/usr/local/nginx/sbin/nginx -V
开启443端口(已关闭防火墙firewalld忽略这一步)
关闭防火墙 systemctl stop firewalld
开启防火墙 systemctl start firewalld
查看防火墙状态: systemctl status firewalld
如果防火墙被开启,则有可能存在443端口没有开启监听的情况
firewall-cmd --zone=public --add-port=443/tcp –permanent
firewall-cmd --reload
查看防火墙里添加的端口
firewall-cmd --list-ports
查看是否在防火墙里开启了443端口监听
netstat -antp|grep 443 结果:
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 2037/nginx:master //代表防火墙开启,并监听了在nginx程序,表示成功。
浏览器端输入https://www.joyce.com 可以查看公钥
注意!最后访问的是https协议!而不是http!
在浏览器里输入https://www.joyce.com/ 即可访问成功!

nginx1.14.0版本https加密配置的更多相关文章
- nginx1.14.0版本负载均衡配置
upstream配置: upstream upstream1 { server 192.168.10.130:8080; server 192.168.10.140:8080; #server 192 ...
- nginx1.14.0版本location路径配置四种方式
假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问. 第一种:location /proxy/ { proxy_pass http:// 12 ...
- nginx1.14.0版本server、location、rewrite配置
server配置demo 在192.168.10.140(centos7)上修改: /home/program/nginx/conf/nginx.conf 添加一个server server { li ...
- nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别
1.多级目录配置 多级目录是指像/html/mypage 等等配置: server { listen 80; server_name localhost; location = /page1/ { # ...
- nginx1.14.0版本高可用——keepalived双机热备
nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...
- elementaryos5安装mysql5.7、php7.2、nginx1.14.0
一.mysql5.7 安装mysql5.7: sudo apt-get install mysql-server-5.7 查看安装的mysql版本: mysql -V 5.7版本mysql安装过程中以 ...
- Nginx1.14.0+ModSecurity实现简单的WAF
一.编译安装Nginx 1.安装依赖环境 $ yum -y install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel ...
- nexus3.14.0版本linux环境安装、启动、搭建私库
本文介绍的是nexus3.14.0版本在linux环境下安装.启动.搭建私库. nexus3以上的版本太新了,网上很少介绍安装细节的.据了解和2.X版本有所不同了. 1.前提 linux机器上需先安装 ...
- CentOS 安装Nginx1.14.0
原文地址:http://www.cnblogs.com/ascd-eg/p/9275441.html 一.安装所需环境 1.gcc 安装 yum install gcc-c++ ...
随机推荐
- dos5章
一.用set命令设置自定义变量 显示.设置或删除 cmd.exe 环境变量. SET [variable=[string]]variable 指定环境变量名.string 指定要指派给变量的一系列字符 ...
- Idea常用功能汇总
1.格式化代码:Ctrl+Alt+L 2.重命名变量:光标停留在变量上,Shift+F6 3.打开文件或者项目所在目录: 右键>Show in Explorer 4.添加包围代码块的快捷键:Ct ...
- openSUSE XFCE桌面 多媒体解码器安装
openSUSE15 leap 在终端命令行安装编解码器: 添加必要的软件源 zypper addrepo -f http://packman.inode.at/suse/openSUSE_Leap_ ...
- 鼠标跟随效果 vue或者js通用
this.$refs.tooltip.getBoundingClientRect() => 用于获取某个元素相对于视窗的位置集合.集合中有top, right, bottom, left等属性. ...
- org.springframework.beans.factory.BeanCreationException 解决异常错误
一月 18, 2017 10:18:51 上午 org.apache.coyote.http11.Http11Protocol initINFO: Initializing Coyote HTTP/1 ...
- python3+cv2+andiord安卓摄像头
#coding=utf-8import cv2 import time if __name__ == '__main__': cv2.namedWindow("camera",1) ...
- SQL 姓名,联系方式-脱敏
SELECT ORDER_PROJECT.project_type AS attribute, ORDER_PROJECT.order_num, ,), "*") AS pv, C ...
- 虚拟机中ubuntu不能联网问题的解决——NAT方式
困惑我多时的Ubuntu联网问题终于解决啦,开心!!!现记录如下,方便日后取用. 可先直接尝试第3步,若不行,则走完全程. 1.查看/设置下NAT的网络 打开VMware Workstation, 点 ...
- bbs项目学习到的知识点(orm中的extra)
注册 form组件给input 的标签 添加样式类 参见这篇博客(点击) 上传图像 1.解决 一点击图像就会直接打开上传文件的按钮 #这儿利用了 label标签和input的特殊的联动功能 < ...
- pivot 与 unpivot 函数是SQL05新提供的2个函数
pivot 与 unpivot 函数是SQL05新提供的2个函数 ----------------------------------------------------------------- ...