1、Winodw安装openssl工具(生成SSL证书用的)免编译版本下载:

http://slproweb.com/products/Win32OpenSSL.html

注意:如果openssl在使用过程中报无法读取conf文件,重启下电脑就好了

Cmd里面的全部命令:

C:\OpenSSL-Win64>cd bin

C:\OpenSSL-Win64\bin>openssl genrsa -des3 -out ssd.key 1024

Generating RSA private key, 1024 bit long modulus

....++++++

........++++++

e is 65537 (0x10001)

Enter pass phrase for ssd.key:    ---123456

Verifying - Enter pass phrase for ssd.key:  ---123456

C:\OpenSSL-Win64\bin>openssl req -new -key ssd.key -out ssd.csr

Enter pass phrase for ssd.key:   ---123456

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) [AU]:cn

State or Province Name (full name) [Some-State]:guangdong

Locality Name (eg, city) []:zhuhai

Organization Name (eg, company) [Internet Widgits Pty Ltd]:ssd

Organizational Unit Name (eg, section) []:ssd

Common Name (e.g. server FQDN or YOUR name) []:yuange

Email Address []:1871707128@qq.com

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:ssd

C:\OpenSSL-Win64\bin>openssl x509 -req -days 36500 -shal -extensions v3_ca -sign

key ssd.key -in ssd.csr -out ssd.crt

unknown option -shal             ----这里面错的原因是:sha1不是shal

usage: x509 args

-inform arg     - input format - default PEM (one of DER, NET or PEM)

-outform arg    - output format - default PEM (one of DER, NET or PEM)

-keyform arg    - private key format - default PEM

-CAform arg     - CA format - default PEM

-CAkeyform arg  - CA key format - default PEM

-in arg         - input file - default stdin

-out arg        - output file - default stdout

-passin arg     - private key password source

-serial         - print serial number value

-subject_hash   - print subject hash value

-subject_hash_old   - print old-style (MD5) subject hash value

-issuer_hash    - print issuer hash value

-issuer_hash_old    - print old-style (MD5) issuer hash value

-hash           - synonym for -subject_hash

-subject        - print subject DN

-issuer         - print issuer DN

-email          - print email address(es)

-startdate      - notBefore field

-enddate        - notAfter field

-purpose        - print out certificate purposes

-dates          - both Before and After dates

-modulus        - print the RSA key modulus

-pubkey         - output the public key

-fingerprint    - print the certificate fingerprint

-alias          - output certificate alias

-noout          - no certificate output

-ocspid         - print OCSP hash values for the subject name and public key

-ocsp_uri       - print OCSP Responder URL(s)

-trustout       - output a "trusted" certificate

-clrtrust       - clear all trusted purposes

-clrreject      - clear all rejected purposes

-addtrust arg   - trust certificate for a given purpose

-addreject arg  - reject certificate for a given purpose

-setalias arg   - set certificate alias

-days arg       - How long till expiry of a signed certificate - def 30 days

-checkend arg   - check whether the cert expires in the next arg seconds

exit 1 if so, 0 if not

-signkey arg    - self sign cert with arg

-x509toreq      - output a certification request object

-req            - input is a certificate request, sign and output.

-CA arg         - set the CA certificate, must be PEM format.

-CAkey arg      - set the CA key, must be PEM format

missing, it is assumed to be in the CA file.

-CAcreateserial - create serial number file if it does not exist

-CAserial arg   - serial file

-set_serial     - serial number to use

-text           - print the certificate in text form

-C              - print out C code forms

-md2/-md5/-sha1/-mdc2 - digest to use

-extfile        - configuration file with X509V3 extensions to add

-extensions     - section from config file with X509V3 extensions to add

-clrext         - delete extensions before signing and input certificate

-nameopt arg    - various certificate name options

-engine e       - use engine e, possibly a hardware device.

-certopt arg    - various certificate text options

-checkhost host - check certificate matches "host"

-checkemail email - check certificate matches "email"

-checkip ipaddr - check certificate matches "ipaddr"

C:\OpenSSL-Win64\bin>openssl x509 -req -days 36500  -extensions v3_ca -signkey s

sd.key -in ssd.csr -out ssd.crt

Signature ok

subject=/C=cn/ST=guangdong/L=zhuhai/O=ssd/OU=ssd/CN=yuange/emailAddress=18717071

28@qq.com

Getting Private key      --123456

Enter pass phrase for ssd.key:    --123456

C:\OpenSSL-Win64\bin>openssl genrsa -des3 -out server.key 2048

Generating RSA private key, 2048 bit long modulus

.........................................+++

...+++

e is 65537 (0x10001)

Enter pass phrase for server.key:  ---123456

Verifying - Enter pass phrase for server.key:  ---123456

C:\OpenSSL-Win64\bin>openssl req -new -key server.key -out server.csr

Enter pass phrase for server.key:   ---123456

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) [AU]:cn

State or Province Name (full name) [Some-State]:guangdong

Locality Name (eg, city) []:zhuhai

Organization Name (eg, company) [Internet Widgits Pty Ltd]:ssd

Organizational Unit Name (eg, section) []:ssd

Common Name (e.g. server FQDN or YOUR name) []:yuange

Email Address []:1871707128@qq.com

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:ssd

C:\OpenSSL-Win64\bin>openssl x509 -req -days 36500 -md5 -extensions v3_req -CA s

sd.crt -CAkey ssd.key -CAcreateserial -in server.csr -out server.crt

Signature ok

subject=/C=cn/ST=guangdong/L=zhuhai/O=ssd/OU=ssd/CN=yuange/emailAddress=18717071

28@qq.com

Getting CA Private Key   ---123456

Enter pass phrase for ssd.key:  ---123456

以上的密码全部都是123456

注意:以上生成的证书保存在openssl/bin目录下,然后把生成的证书拷贝到nginx/conf的目录下,在这里面我只拷贝了server.crt  、server.key

2、什么都配置好后发现:

Nginx -t 编译成功,但是运行的时候就自动关闭了,查看日志的时候报错了:

查了好久,终于知道了原因:

Windows下的nginx配置ssl的key是不能存储密码的,否则就会报这个错

解决办法:

在cmd中cd 到openssl/bin的目录下,输入:

Openssl rsa -in  C:\OpenSSL-Win64\bin\server.key  -out c:/server.key.unsecure

输入server.key当初设置的密码,这里面是123456

然后在C根目录下可以看到:成功

把server.key.unsecure替换在nginx.conf文件中的server.key内容  即可

3、配置nginx.conf

 #使用的用户和组,window下不指定
#user nobody;
#指定工作衍生进程数(一般等于CPU总和数或总和数的两倍,例如两个四核CPU,则总和数为8)
worker_processes 3;
#指定错误日志文件存放路径,错误日志级别可选项为【debug|info|notice|warn|error|crit】
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放路径
#pid logs/nginx.pid; #工作模式及连接数上限
events {
#使用网络I/O模型,Linux系统推荐使用epoll模型,FreeBSD系统推荐使用kqueue;window下不指定
#use epoll;
#允许的连接数
worker_connections 1024;
} #设定http服务器,利用他的反向代理功能提供负载均衡支持
http {
#设定mime类型
include mime.types;
default_type application/octet-stream;
#设定日志格式
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #设定请求缓冲
client_header_buffer_size 1k;
large_client_header_buffers 4 4k; #设定access log
#access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m; sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65; #开启gzip模块
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml; output_buffers 1 32k;
postpone_output 1460; server_names_hash_bucket_size 128;
client_max_body_size 8m; fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_vary on; #设定负载均衡的服务器列表
upstream url{
#根据ip计算将请求分配各那个后端tomcat,可以解决session问题
#ip_hash;
#同一机器在多网情况下,路由切换,ip可能不同
#weigth参数表示权值,权值越高被分配到的几率越大
#server localhost:8080 weight=1;
#server 10.152.252.160:8443 weight=2;
#server 10.152.252.162:8443 weight=20;
server 10.152.252.160:8443 max_fails=2 fail_timeout=600s;
server 10.152.252.162:8443 max_fails=2 fail_timeout=600s;
} #设定虚拟主机
server {
listen 8080;
#server_name 10.152.252.160; #proxy_pass https://url;
rewrite ^(.*)$ https://$host:8443$1 permanent;
#charset koi8-r;
charset UTF-8;
#设定本虚拟主机的访问日志
#access_log logs/host.access.log main; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# HTTPS server
server {
listen 443;
listen 8444;
server_name 10.152.252.160; ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key.unsecure; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
root html;
index index.html index.htm; proxy_redirect off;
#保留用户真实信息
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m; proxy_pass https://url;
}
}
}

nginx 配置https 负载均衡的更多相关文章

  1. office web apps安装部署,配置https,负载均衡(七)配置过程中遇到的问题详细解答

    该篇文章,是这个系列文章的最后一篇文章,该篇文章将详细解答owa在安装过程中常见的问题. 如果您没有搭建好office web apps,您可以查看前面的一系列文章,查看具体步骤: office we ...

  2. office web apps安装部署,配置https,负载均衡(六)配置负载均衡

    owa可以采用任何的负载均衡方案,我们这里采用阿里云提供的负载均衡解决方案 前提条件,你已经配置了一台域控制器,两台域服务器[即安装了owa相关软件,并将计算机隶属于域]: 如果您不清楚怎么做,那么请 ...

  3. office web apps安装部署,配置https,负载均衡(五)配置服务器场

    前提条件:您已经完成了域控制器的配置,拥有域账号,并且已经安装了OWA启动所需要的必要软件: 具体步骤可以参考: office web apps安装部署,配置https,负载均衡(一)背景介绍 off ...

  4. office web apps安装部署,配置https,负载均衡(四)安装office web apps相关软件

    前提条件: 1.一台windows server 2008R2服务器,并且已经配置了域: 服务器连接域控制器的相关文档,请查看上一篇文章: office web apps安装部署,配置https,负载 ...

  5. office web apps安装部署,配置https,负载均衡(三)服务器连接域控制器

    前提条件:1>一台window server 2008R2 服务器 2>您已经在同一内网的另外一台服务器上安装好了域控制器文档请看我写的另外一篇文章: office web apps安装部 ...

  6. 使用nginx+docker配置https负载均衡

    了解Docker Docker是一个golang编写的开源轻量级的.可移植的.自给自足的容器,Docker主要应用在以下场景: web应用的自动化打包和发布: 自动化测试和持续集成.发布: 在服务型环 ...

  7. Nginx配置之负载均衡、限流、缓存、黑名单和灰度发布

    一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...

  8. Nginx配置及负载均衡

    转载:http://www.cnblogs.com/jingmoxukong/p/5945200.html nginx简易教程   目录 Nginx  概述  安装与使用  nginx 配置实战  参 ...

  9. nginx配置优化+负载均衡+动静分离详解

    nginx配置如下: #指定nginx进程运行用户以及用户组user www www;#nginx要开启的进程数为8worker_processes 8;#全局错误日志文件#debug输出日志最为详细 ...

随机推荐

  1. 通过批处理 安装 mongodb和设置身份验证

    1.首先需要 mongodb.msi安装包 2.mongodb的配置文件mongod.cfg 内容如下: systemLog: destination: file path: "D:/mon ...

  2. web基础之会话技术

    一.会话技术之Cookie Cookie技术是将数据存储到客户端 1.怎样去向客户端写出一个cookie 1)创建Cookie对象 Cookie cookie = new Cookie(name,va ...

  3. 运维老鸟教你安装centos6.5如何选择安装包

    标签:老男孩教育 Centos6.5安装选包原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.c ...

  4. Natas Wargame Level 17 Writeup(Time-based Blind SQL Injection)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIAAACUCAYAAABvE8qCAAAABHNCSVQICAgIfAhkiAAAIABJREFUeF

  5. 读Zepto源码之集合操作

    接下来几个篇章,都会解读 zepto 中的跟 dom 相关的方法,也即源码 $.fn 对象中的方法. 读Zepto源码系列文章已经放到了github上,欢迎star: reading-zepto 源码 ...

  6. Nodejs基础:stream模块入门介绍与使用

    本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. 模块概览 nodejs的核心模块,基本上都是stream的的实例 ...

  7. 《JAVA与模式》之命令模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述命令(Command)模式的: 命令模式属于对象的行为模式.命令模式又称为行动(Action)模式或交易(Transaction)模式. ...

  8. struts2.1.6教程一、准备工作及实例

    1.解压struts-2.1.6-all.zip apps目录:struts2自带的例子程序 docs目录:官方文档. lib 目录:存放所有jar文件. Src 目录:源文%件存放地 2.六个基本包 ...

  9. 五、 创建连接串连接本地数据库(ASP.NET MVC5 系列)

    1. 创建连接串连接本地SQLServer数据库 上节讲到MovieDBContext类,这个类的作用是连接数据库并将Movie对象迁移到数据库记录中.不过你会问一个问题:如何知道这个对象将连接哪个数 ...

  10. Junit4测试Spring

    使用Junit4.4测试 在类上的配置Annotation  @RunWith(SpringJUnit4ClassRunner.class) 用于配置spring中测试的环境  @ContextCon ...