需求

最近公司在做全站https,架构上面有Nginx+tomcat Nginx+php,且nginx配置了ssl,tomcat和php项目使用https协议

但是,发送的是https url请求,php和tomcat的log里面记录的都是http的请求。

解决方法很简单,只需要分别配置一下 Nginx 和 Tomcat 就好了,而不用改程序。

配置 Nginx 的转发选项:
server {
listen 443 ssl http2;
server_name new.m.abc.com m.abc.com;
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
ssl_certificate /etc/nginx/conf.d/ssl/abc.com.crt;
ssl_certificate_key /etc/nginx/conf.d/ssl/abc.com.key;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
access_log /var/log/nginx/new.m.abc.log main;
set $web_url $host;
if ($request_uri ~* /h5/index.html)
{
rewrite ^/(.*)$ http://m.abc.com permanent;
}
limit_req zone=anti_spider burst=1 nodelay;
if ($http_user_agent ~* "qihoobot|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp Ch
ina|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
{
set $anti_spider $http_user_agent;
}
location / {
proxy_pass http://web.server;
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;
set $domain default;
}
}

proxy_set_header X-Forwarded-Proto $scheme;

配置Tomcat server.xml 的 Engine 模块下配置一个 Valve:
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>

配置双方的 X-Forwarded-Proto 就是为了正确地识别实际用户发出的协议是 http 还是 https。

测试就都变为正确的结果了,就像用户在直接访问 Tomcat 一样。

如果是php提供服务,无需修改php代码及配置。

Nginx配置X-Forwarded-Proto的更多相关文章

  1. Nginx负载均衡、SSL原理、生成SSL密钥对、Nginx配置SSL

    6月12日任务 12.17 Nginx负载均衡12.18 ssl原理12.19 生成ssl密钥对12.20 Nginx配置ssl扩展 针对请求的uri来代理 http://ask.apelearn.c ...

  2. nginx配置反向代理或跳转出现400问题处理记录

    午休完上班后,同事说测试站点访问接口出现400 Bad Request  Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...

  3. Windos环境用Nginx配置反向代理和负载均衡

    Windos环境用Nginx配置反向代理和负载均衡 引言:在前后端分离架构下,难免会遇到跨域问题.目前的解决方案大致有JSONP,反向代理,CORS这三种方式.JSONP兼容性良好,最大的缺点是只支持 ...

  4. Windows下Nginx配置SSL实现Https访问(包含证书生成)

    Vincent.李   Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...

  5. Nginx 配置简述

    不论是本地开发,还是远程到 Server 开发,还是给提供 demo 给人看效果,我们时常需要对 Nginx 做配置,Nginx 的配置项相当多,如果考虑性能配置起来会比较麻烦.不过,我们往往只是需要 ...

  6. Nginx配置详解

    序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也 ...

  7. Nginx配置Https

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

  8. nginx配置为windows服务中的坑

    网上搜索“nginx 配置为windows服务”,很容易搜索到使用windows server warpper来配置,于是按照网上的方法我从github上的链接下载了1.17版本,前面都很顺利,很容易 ...

  9. 【nginx配置】nginx做非80端口转发

    一个场景 最近在使用PHP重写一个使用JAVA写的项目,因为需要查看之前的项目,所以要在本地搭建一个Tomcat来跑JAVA的项目.搭建成功后,因为Tomcat监听的端口是8080,因此,访问的URL ...

  10. Apache、nginx配置的网站127.0.0.1可以正常访问,内外网的ip地址无法访问,谁的锅?

    最近做开发,发现一个比较尴尬的问题.因为我是一个web开发者,经常要用到Apache或者nginx等服务器软件,经过我测试发现,只要我打开了adsafe,我便不能通过ip地址访问我本地的网站了,比如我 ...

随机推荐

  1. ZOJ 3715 Kindergarten Election

    At the beginning of the semester in kindergarten, the n little kids (indexed from 1 to n, for conven ...

  2. 【转载】Java并发编程:volatile关键字解析

    http://www.cnblogs.com/dolphin0520/p/3920373.html

  3. js 一些基础知识

    数据类型: 作用域 每个函数都有自己的执行环境,执行环境定义了变量有权访问的其他数据,决定了他们各自的行为. 每个执行环境都有一个与之关联的变量对象(variable object),环境中定义的所有 ...

  4. LeetCode_Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  5. 【react redux && flux】

    redux: http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_three_react-redux.html https://bai ...

  6. Drainage Ditches---hdu1532(最大流, 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最大流模板题: EK:(复杂度为n*m*m); #include<stdio.h> ...

  7. GNU Screen使用入门

    前些天开始学习使用GNU Screen程序,发现这个工具在管理服务器时候确实挺方便的,于是写一篇文章总结一下,顺便介绍Screen的基本使用方法. 简介 GNU Screen是 一个基于文本的全屏窗口 ...

  8. Code signing is required for product type 'Application' in SDK 'iOS 11.2'

    在打包的时候出现这样一个错误,Code signing is required for product type 'Application' in SDK 'iOS 11.2'  ,就是说代码签名证书 ...

  9. 在vue中使用express-mock搭建mock服务

    首先安装 nodemon ,如果是全局安装,那么所有的项目都可以使用mock服务 npm install nodemon 再安装express-mockjs npm i -D express-mock ...

  10. hbase(一)

    1.hbase安装参考 http://blog.csdn.net/wild46cat/article/details/53214159 2.遇到的问题: ERROR: The node /hbase ...