修改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加密配置的更多相关文章

  1. nginx1.14.0版本负载均衡配置

    upstream配置: upstream upstream1 { server 192.168.10.130:8080; server 192.168.10.140:8080; #server 192 ...

  2. nginx1.14.0版本location路径配置四种方式

    假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问. 第一种:location /proxy/ {    proxy_pass http:// 12 ...

  3. nginx1.14.0版本server、location、rewrite配置

    server配置demo 在192.168.10.140(centos7)上修改: /home/program/nginx/conf/nginx.conf 添加一个server server { li ...

  4. nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别

    1.多级目录配置 多级目录是指像/html/mypage 等等配置: server { listen 80; server_name localhost; location = /page1/ { # ...

  5. nginx1.14.0版本高可用——keepalived双机热备

    nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...

  6. 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安装过程中以 ...

  7. Nginx1.14.0+ModSecurity实现简单的WAF

    一.编译安装Nginx 1.安装依赖环境 $ yum -y install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel ...

  8. nexus3.14.0版本linux环境安装、启动、搭建私库

    本文介绍的是nexus3.14.0版本在linux环境下安装.启动.搭建私库. nexus3以上的版本太新了,网上很少介绍安装细节的.据了解和2.X版本有所不同了. 1.前提 linux机器上需先安装 ...

  9. CentOS 安装Nginx1.14.0

    原文地址:http://www.cnblogs.com/ascd-eg/p/9275441.html 一.安装所需环境   1.gcc 安装         yum install gcc-c++   ...

随机推荐

  1. kettle并行运行时出现「Unknown error in KarafBlueprintWatcher」

    背景:在使用kettle 6进行大量数据并行抽取时,偶尔会出现「Unknown error in KarafBlueprintWatcher」的错误,详细的报错信息可以查看下面的代码块. ERROR: ...

  2. Android KitKat Immersive Mode使用

    写了一个方法,在onCreate和onResume中调用即可,4.4以上可用. private void openImmersiveMode() { if (android.os.Build.VERS ...

  3. JAVA日常之三

    一.Main方法的args参数 args[] 是程序运行前可传入的参数,比如 java HelloWorld a,那么在HelloWorld的main方法里面 args就是{"a" ...

  4. css ——行级元素与块级元素解析

    一 . 先说说二者的本质区别吧:        行级元素是可以和其他元素处于一行,不用必须另起一行.块级元素是每个块级元素都是独自占一行,其后的元素也只能另起一行,并不能两个元素共用一行. 二 .下面 ...

  5. linux文件查找find命令

    linux文件查找find命令 1.文件查找 基本介绍 在文件系统上查找符合条件的文件 linux上常见的文件查找工具:find命令 查找分类 实时查找 精确查找 基本语法 find  [option ...

  6. Java基于opencv—矫正图像

    更多的时候,我们得到的图像不可能是正的,多少都会有一定的倾斜,就比如下面的 我们要做的就是把它们变成下面这样的 我们采用的是寻找轮廓的思路,来矫正图片:只要有明显的轮廓都可以采用这种思路 具体思路: ...

  7. css animate

    AniX https://a-jie.github.io/AniX/

  8. Windows Server 2012配置iis遇到的问题

    发布网站访问时报500 - 内部服务器错误,经排查是Windows Server 2012上的iis配置有问题,有些需要的功能没有配置. 在重新配置iis时总是安装失败,提示存储空间不足. 在网上查找 ...

  9. 各类排序算法的实现C#版

    using System;using System.CodeDom;using System.Collections.Generic;using System.Linq;using System.Ru ...

  10. 3,列表的 深 浅 copy

    如果列表只有一层,深浅copy是一样一样的,没有什么区别,你修改了copy后的列表,copy前的列表并不会随之改变. 如果列表中嵌套这列表,这是你修改了copy后第二层列表里面的元素,copy前第二层 ...