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++ ...
随机推荐
- centos7 安装mysql出现Could NOT find Curses (missing CURSES_LIBRARY CURSES_INCLUDE_PATH)
今天安装mysql 5.7 编译时出现一下问题: [root@localhost software]# cd mysql-5.7.21 [root@localhost mysql-5.7.21]# c ...
- C语言链表:逆序建立单链表
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<malloc.h> #define LEN sizeof( ...
- unicode,gbk,utfF-8字符编码方式的区别
一.编码历史与区别 一直对字符的各种编码方式懵懵懂懂,什么ANSI UNICODE UTF-8 GB2312 GBK DBCS UCS……是不是看的很晕,假如您细细的阅读本文你一定可以清晰的理解他们. ...
- 百川sdk----自己的WebViewClient不被执行【废弃,新版本百川已修复此问题】
我在百川sdk的旺旺群中,追问这个问题N多次,一直没有人答复,哎,凡事都要靠自己..... 1.先查看下百川sdk中,是怎么处理咱们传递过去的 WebViewClient public class l ...
- word中插入myth type公式行距变大的问题
在写文章时,我遇到了在word中插入myth type公式时,行距明显变大的问题,我通过改变段落中的行距没有解决问题,在网上查了一下,找到一些解决方法,仅供参考. 解决办法
- PHP 多维数组排序 函数怎么保持数字键不被重新索引
/** * 根据数组中的某个键值大小进行排序,仅支持二维数组 * * @param array $array 排序数组 * @param string $key 键值 * @param bool $a ...
- linux 修改配色
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ " ORvim ~/ ...
- java 环境的安装、设置免密登陆、进行hadoop安装、关闭防火墙
1.去这个网站下载对应的版本:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html我这 ...
- Python之删除空白
Python能够找出字符串开头.末尾.两端多余的空白. lstrip()方法可以剔除字符串开头的空白: rstrip()方法可以剔除字符串末尾的空白: strip()可以剔除字符串两端的空白: fav ...
- Zend studio快捷键使用
应用场景 快捷键 功能 查看快捷键 ctrl+shift+l 显示所有快捷键列表 查看和修改快捷键 打开Window->Preferences->General->keys 修改 ...