nginx proxy https
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没有证书的话,可以如此简化:
代码如下:
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;”这一行
说明:
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中添加:
- server {
- ### server port and name ###
- listen 443 ssl;
- server_name member.aoshiwei.com;
- ssl on;
- ### SSL log files ###
- access_log logs/ssl-access.log;
- error_log logs/ssl-error.log;
- ### SSL cert files ###
- ssl_certificate ssl/aoshiwei.com.crt;
- ssl_certificate_key ssl/aoshiwei.com.key;
- ### Add SSL specific settings here ###
- keepalive_timeout 60;
- ### Limiting Ciphers ########################
- # Uncomment as per your setup
- #ssl_ciphers HIGH:!ADH;
- #ssl_perfer_server_ciphers on;
- #ssl_protocols SSLv3;
- ##############################################
- ### We want full access to SSL via backend ###
- location / {
- proxy_pass http://member.aoshiwei.com;
- ### force timeouts if one of backend is died ##
- proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
- ### Set headers ####
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- ### Most PHP, Python, Rails, Java App can use this header ###
- proxy_set_header X-Forwarded-Proto https;
- ### By default we don't want to redirect it ####
- proxy_redirect off;
- }
- }
nginx proxy https的更多相关文章
- Keepalivaed +Nginx proxy 高可用架构方案与实施过程细节
1.开源产品介绍 1)CMS介绍 官方网站http://www.dedecms.com/,是一个网站应用系统构建平台,也是一个强大的网站内容管理系统,既可以用来构建复杂的体系的企业信息门户或者电子商务 ...
- nginx配置https域名
nginx安装配置支持https和配置https域名 yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-de ...
- nginx proxy pass redirects ignore port
nginx proxy pass redirects ignore port $host in this order of precedence: host name from the request ...
- Docker Nginx-Proxy 容器Nginx Proxy反向代理
Docker Nginx-Proxy 容器Nginx Proxy反向代理 简单介绍 Docker容器的自动Nginx反向代理 dockerhub地址 https://hub.docker.co ...
- nginx代理https站点(亲测)
nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...
- Nginx配置Https
1.申请证书: https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qc ...
- Nginx采用https加密访问后出现的问题
线上的一个网站运行了一段时间,应领导要求,将其访问方式更改为https加密方式.更改为https后,网站访问正常,但网站注册功能不能正常使用了! 经过排查,是nginx配置里结合php部分漏洞了一个参 ...
- nginx proxy超时报错 upstream timed out (110: Connec...
环境介绍 服务器:centos6.4服务:nginx proxy 问题描述: 然后查找 /opt/usr/nginx/1.4.0/logs 错误 error.log日志提示如下 2015/01/0 ...
- 【转】Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
随机推荐
- Jenkins系列之-—08 实现SQL脚本批量执行
公司内部推广DevOps,所有目前在维护阶段和开发阶段项目全部配置上了自动发布.采用Jenkins+SVN+ANT,之后批量执行SQL语句的实现提上日程 一.环境 Linux环境 安装ANT工具,且下 ...
- http 错误代码一览表
http协议一些常见的状态码为: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分 ...
- 怎样在C语言里实现“面向对象编程”
有人觉得面向对象是C++/Java这样的高级语言的专利,实际不是这样.面向对象作为一种设计方法.是不限制语言的.仅仅能说,用C++/Java这样的语法来实现面向对象会更easy.更自然一些. 在本节中 ...
- Ubuntu16.04上安装mongoDB
安装MongoDB 现在最新版本是3.4 1: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F37303 ...
- qemu-kvm编译错误
今天编译了下qemu-kvm,死活编不过,错误信息如下: CC block/qcow2-snapshot.oIn file included from ./qemu-common.h:6:0, ...
- javaScript中innerHTML,innerText,outerHTML,outerText的区别
开头说下innerText和outerText只在chrome浏览器中有效 定义和用法 innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML,包括标签. 来看代码 <!DOC ...
- JavaScript+Json写的二级联动
省市区的联动,相当常见 我就不写这么大数据的了,先写个简单的试一试 <!DOCTYPE html> <html> <head> <title></ ...
- VS2005 调试不能设置断点的解决办法
[ 1] 以前也遇到过同样的问题,但没有问个为什么,也没有探个毕竟.昨天调试一个DLL,添加输出信息吧,太麻烦而且不轻易定位, 但设置断点后按“F5”,断点不可用,气泡提示“当前不会命中断点,还没有为 ...
- 我读过的最好的epoll讲解
首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象. 不管是文件,还是套接字,还是管道,我们都可以把他们看作流. 之后我们来讨论I ...
- 最简单的 IntelliJ IDEA 中使用 GitHub 进行版本控制教程(持续更新中)
一.在 IntelliJ IDEA 中新建一个项目并提交到 GitHub 1. 运行 IDEA,点击[Create New Project],在 IDEA 中新建一个项目. 2. 在选择项目类型对话框 ...