server {
listen 443;
server_name mail.jb51.net;

ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;

location / {
proxy_pass https://192.168.0.2:443;

proxy_set_header Host $host:443;
proxy_set_header X-Real-IP
$remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";

}
}

其中192.168.0.2是你的https主机
如果后端https没有证书的话,可以如此简化:

复制代码
代码如下:
server {
listen 80;
server_name
svn.jb51.net;

location / {
proxy_pass https://192.168.0.2:443;

proxy_set_header Host $host:443;
proxy_set_header X-Real-IP
$remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";

proxy_set_header X-Forwarded-Proto https; #注意看这里 多了一行
}
}

如果提示“SSL 接收到一个超出最大准许长度的记录。” 错误代码“ssl_error_rx_record_too_long”说明少了“ssl
on;”这一行

Nginx 反向代理https

说明:

1.nginx 1.2.0 centos 6.2
2.这里所指的反向代理https是指nginx为ssl服务器,nginx与后端服务器的通信还是http,当然可能也可以实现nginx与后端服务器实现https通信,不过本文没有测试

步骤:
nginx要实现ssl,在编译时要添加--with-http_ssl_module,如:
./configure --with-http_ssl_module

#cd /usr/local/nginx/conf
#mkdir ssl
#cd ssl
生成一个私有key
# openssl genrsa -des3 -out aoshiwei.com.key 1024
提示输入密码
生成CSR(Certificate Signing Request)文件:
# openssl req -new -key aoshiwei.com.key -out aoshiwei.com.csr
填写证书内容,组织机构、域名等,Common Name填写域名
 
# cp aoshiwei.com.key aoshiwei.com.key.bak
# openssl rsa -in aoshiwei.com.key.bak -out aoshiwei.com.key
# openssl x509 -req -days 365 -in aoshiwei.com.csr -signkey aoshiwei.com.key -out aoshiwei.com.crt

在nginx.conf中添加:

  1. server {
  2. ### server port and name ###
  3. listen          443 ssl;
  4. server_name     member.aoshiwei.com;
  5. ssl on;
  6. ### SSL log files ###
  7. access_log      logs/ssl-access.log;
  8. error_log       logs/ssl-error.log;
  9. ### SSL cert files ###
  10. ssl_certificate      ssl/aoshiwei.com.crt;
  11. ssl_certificate_key  ssl/aoshiwei.com.key;
  12. ### Add SSL specific settings here ###
  13. keepalive_timeout    60;
  14. ###  Limiting Ciphers ########################
  15. # Uncomment as per your setup
  16. #ssl_ciphers HIGH:!ADH;
  17. #ssl_perfer_server_ciphers on;
  18. #ssl_protocols SSLv3;
  19. ##############################################
  20. ### We want full access to SSL via backend ###
  21. location / {
  22. proxy_pass  http://member.aoshiwei.com;
  23. ### force timeouts if one of backend is died ##
  24. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  25. ### Set headers ####
  26. proxy_set_header Host $host;
  27. proxy_set_header X-Real-IP $remote_addr;
  28. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  29. ### Most PHP, Python, Rails, Java App can use this header ###
  30. proxy_set_header X-Forwarded-Proto https;
  31. ### By default we don't want to redirect it ####
  32. proxy_redirect     off;
  33. }
  34. }

nginx proxy https的更多相关文章

  1. Keepalivaed +Nginx proxy 高可用架构方案与实施过程细节

    1.开源产品介绍 1)CMS介绍 官方网站http://www.dedecms.com/,是一个网站应用系统构建平台,也是一个强大的网站内容管理系统,既可以用来构建复杂的体系的企业信息门户或者电子商务 ...

  2. nginx配置https域名

    nginx安装配置支持https和配置https域名 yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-de ...

  3. nginx proxy pass redirects ignore port

    nginx proxy pass redirects ignore port $host in this order of precedence: host name from the request ...

  4. Docker Nginx-Proxy 容器Nginx Proxy反向代理

    Docker Nginx-Proxy 容器Nginx Proxy反向代理   简单介绍 Docker容器的自动Nginx反向代理   dockerhub地址 https://hub.docker.co ...

  5. nginx代理https站点(亲测)

    nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...

  6. Nginx配置Https

    1.申请证书: https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qc ...

  7. Nginx采用https加密访问后出现的问题

    线上的一个网站运行了一段时间,应领导要求,将其访问方式更改为https加密方式.更改为https后,网站访问正常,但网站注册功能不能正常使用了! 经过排查,是nginx配置里结合php部分漏洞了一个参 ...

  8. nginx proxy超时报错 upstream timed out (110: Connec...

    环境介绍 服务器:centos6.4服务:nginx proxy 问题描述: 然后查找  /opt/usr/nginx/1.4.0/logs  错误 error.log日志提示如下 2015/01/0 ...

  9. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

随机推荐

  1. pjblog支持QQ、新浪微博一键登录

    转载地址: http://www.ruisoftcn.com/blog/article.asp?id=955

  2. GTK入门学习:布局练习之计算器

    接下来,我们做一个布局练习.例如以下图: 我们用表格布局实现,表格布局參考坐标例如以下: 这里我们用到行编辑控件( GtkEntry ). 行编辑的创建: GtkWidget * gtk_entry_ ...

  3. C结构体对齐

    函数模板针对仅参数类型不同的函数?   http://blog.csdn.net/renrenhappy/article/details/5931457     计算结构体的大小就要考虑数据对齐问题. ...

  4. 找回Xcode7的代码折叠功能

    升级到Xcode7后,会发现代码折叠功能不见了,这是怎么回事? 其实这个功能还在的,用以下的快捷键仍然可以折叠代码.只是不能用鼠标实现折叠了:在Xcode菜单里选择Preference——Text E ...

  5. java 堆和栈一般理解

    栈与堆都是Java用来在Ram中存放数据的地方.与C++不同.Java自己主动管理栈和堆.程序猿不能直接地设置栈或堆.  Java的堆是一个执行时数据区,类的(对象从中分配空间.这些对象通过new.n ...

  6. JAVA 数据筛选(第一笔数据与第二笔数据比较)

    第一笔数据与第二笔数据比较 Map<String, Object> jHpictureMap = new HashMap<String, Object>(); // 存放照片S ...

  7. mongoDB之监控工具mongostat及其参数的具体含义

    mongostat是mongdb自带的状态检测工具,在命令行下使用.它会间隔固定时间获取mongodb的当前运行状态,并输出.如果你发现数据库突然变慢或者有其他问题的话,你第一手的操作就考虑采用mon ...

  8. Linux 操作系统中的进程结构

    前言 在 Linux 中,一个正在执行的程序往往由各种各样的进程组成,这些进程除了父子关系,还有其他的关系.依赖于这些关系,所有进程构成一个整体,给用户提供完整的服务( 考虑到了终端,即与用户的交互 ...

  9. iOS开发之NewsstandKit.framework的使用

    本文转载至 http://mobile.51cto.com/iphone-423385.htm   系统提供NewsstandKit.framework来支持newsstand类型的程序,就是在spr ...

  10. php 中 isset 和empty 的区别

    昨天终于开始学习php了,这个对于我来说听着很熟悉,但是学起来很陌生的东西,尤其是课上能听明白 但是真正写起了手生,都不知道手该往哪里放了,天哪~~~ 其中课上有讲到 isset和empty的区别,现 ...