在nginx配置部分https
来源:互联网 发布:常见公钥算法 编辑:程序博客网 时间:2024/06/03 11:17
在昨天的文章(配置https实现请求安全)里,我介绍了nginx配置全站的https访问,这样对所有请求都会加密,会减慢响应速度。
在实际的项目中,我们也没有必要对所有请求加密,比如浏览一个帖子列表,查看一个商品信息等等,只需要对一些包含敏感数据的请求加密就可以了。
因此,今天尝试配置了nginx部分的https访问,这里的测试会继续使用到昨天生成的秘钥和证书,对登陆页面进行加密,配置的代码如下:
upstream site{ server localhost:8081; server localhost:8082; server localhost:8083; } server { listen 9001; server_name localhost; index index.jsp index.html; root /home/default; location ~ .* { proxy_pass http://site; proxy_set_header X-Real-IP $remote_addr; } location ^~ /test/login.jsp{ rewrite ^ https://$server_addr:443$request_uri? permanent; } } server { listen 443 ssl; server_name localhost; ssl on; ssl_certificate /home/dayuanzi/temp/rsamiyao.csr; ssl_certificate_key /home/dayuanzi/temp/rsamiyaonopw.key; location / { rewrite ^ http://$server_addr:9001$request_uri? permanent; } location ^~ /test/login.jsp{ proxy_pass http://127.0.0.1:8081; 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_set_header X-Forwarded-Proto $scheme; } }部署服务器详情:
三台tomcat:
localhost:8081,localhost:8082,localhost:8083
一台nginx
在上面的配置实现了以下功能:1、nginx作为一个负载均衡器,除了login.jsp请求,其他请求都会平均分发到其他三个本地服务器
2、http://localhost:9001/test/login.jsp时,会重定向为https://localhost/test/login.jsp,对login.jsp加密
3、https://localhost/test/* 时,会重定向为http://locathost:9001/* ,一般请求不加密
这里简单说一下rewrite语法:rewrite regex replacement [flag];
flag可以有四个取值:
last : 相当于Apache的[L]标记,表示完成rewrite
break : 停止执行当前虚拟主机的后续rewrite指令集
redirect : 返回302临时重定向,地址栏会显示跳转后的地址
permanent : 返回301永久重定向,地址栏会显示跳转后的地址另外,测试时,如果是在另一台机器访问,上面rewrite ^ http://$server_addr:9001$request_uri?中,必须要用$server_addr不能用$server_name,否则会重定向到本机
- 在nginx配置部分https
- nginx在phpstudy下配置https
- nginx配置ssl加密(单/双向认证、部分https)
- Nginx配置ssl加密(单双向认证、部分https)
- nginx配置ssl加密(单双向认证、部分https)
- Nginx配置ssl加密(单双向认证、部分https)
- nginx配置ssl加密(单双向认证、部分https)
- Nginx(12):nginx配置https
- nginx 配置https server
- nginx 配置https
- Nginx 配置 https 加密
- Nginx配置https服务器
- Ubuntu nginx 配置https
- nginx https配置
- nginx配置https
- nginx 配置https
- nginx 配置HTTPS服务器
- Linux nginx配置https
- mac下连接VirtualBox虚拟机(NAT模式)
- 页面加载时执行js的几种方法
- OpenDaylight Lithium 在ubunbtu下的安装
- 密码 pasuwado题解
- PHP安装扩展mcrypt以及相关依赖项 【PHP安装PECL扩展的方法】
- 在nginx配置部分https
- 洗牌与排序
- jquery-chosen 选择框插件
- 省市二级联动
- IOS百度地图
- shell与bash
- transitionFromViewController方法的使用--优化
- Hexagon处理器的指令编码
- 【烙铁使用规范】—— 延长无铅手工焊接工艺中烙铁头的寿命