nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案
nginx代理tomcat后,tomcat获取服务端ip端口的解决方案
1.注意修改nginx配置代理,标红地方
#user nginx;
worker_processes ; error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; pid logs/nginx.pid; events {
worker_connections ;
} http {
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"'; access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; gzip on;
gzip_disable "MSIE [1-6]."; client_header_buffer_size 128k;
large_client_header_buffers 128k;
############你自己的项目#######
upstream dj-tomcatwebapp {
# sticky;
server 127.0.0.1:;
}
###### 你自己的项目system#######
server {
listen ;
server_name 127.0.0.1; charset utf-8; #access_log logs/host.access.log main; location / {
client_max_body_size 1000m;
proxy_pass http://dj-tomcatwebapp;
proxy_redirect off;
78 proxy_set_header Host $host:$server_port;
79 proxy_set_header X-Real-IP $remote_addr;
80 proxy_set_header X-Real-PORT $remote_port;
82 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; } }
}
2.jsp获取真实服务器 nginx访问 ip 端口
<%
String scheme = request.getScheme();
String serverName = request.getServerName();
int port = request.getServerPort();
String requestURI = scheme+"://"+serverName+":"+port;
%>
<c:set var="hyrt" value="<%=requestURI%>" />
以上经过实际本地测试,可以正常获取
nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案的更多相关文章
- nginx 代理模式下,获取客户端真实IP
最近做博友推荐,发现个小问题,用$_SERVER['REMOTE_ADDR'];得到的都是服务器的地址192.168.96.52,搜索了一下,发现问题,改为$_SERVER['HTTP_X_REAL_ ...
- nginx 代理https后,应用redirect https变成http --转
原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...
- NGINX反向代理,后端服务器获取真实IP
一般使用中间件做一个反向代理后,后端的web服务器是无法获取到真实的IP地址. 但是生产上,这又是不允许的,那么怎么解决? 1.在NGINX反向代理服务器上进行修改 2.修改后端web服务器配置文件 ...
- nginx 代理 https 后,应用变成 http
需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...
- Eclipse-ee 启动Tomcat后浏览器无法访问Tomat,并且Web项目服务部署
环境: Ubuntu 14.04 + Eclipse-ee + Tomcat7 问题: 在Eclipse中建立Server时选择的Tomcat7,Server的运行时选择的时自己安装的Tomcat目 ...
- 有关于腾讯地图服务端IP定位接口的获取当前城市的处理
接口说明:http://apis.map.qq.com/ws/location/v1/ip 说明里面写了ip可以缺省,然并卵,经过测试的到结果并不能获取到当前城市,理由是腾讯ip库的对应ip精度没有定 ...
- 获取与esp8266连接的客户端的Mac地址 IP 端口 控制停止等问题
两个关键的库 ESP8266WebServer.h WiFiClient.h ESP8266WiFiAP.cpp C:\Users\dongdong\Desktop\Arduino-master\li ...
- js获取服务端IP及端口及协议
alert("location:"+window.location); alert("href: "+window.location.href); alert( ...
- nginx代理后,获取request的ip
应用程序部署上线,一般都会用nginx之类的来进行反向代理,而不是直接访问tomcat之类的容器. 这时候如果用平时的获取ip的代码,就只会获取到nginx所在服务器的ip, 就失去了本身的意义. 今 ...
随机推荐
- 修改tomcat的get方法的参数长度
在solr查询中,遇到查询字符串过长,返回错误,在tomcat的conf/server.xml中修改下面的参数即可.加上maxHttpHeaderSize="65536" < ...
- Nginx 502/504 Gateway time-out错误完美解决方案【转发】
在安装完Nginx+PHP-fpm+Mysql后,跑PHP的应用会经常出现504 Gateway Time-out 或者502 Bad Gateway的情况. Nginx 504 Gateway ...
- xshell 图形化连接ubuntu
原文: http://jingyan.baidu.com/article/d45ad148967fcd69552b80f6.html Xmanager4系列软件是一套非常好的liunx远程操作,尤其是 ...
- 素数路(prime)
素数路(prime) 题目描述 已知一个四位的素数,要求每次修改其中的一位,并且要保证修改的结果还是一个素数,还不能出现前导零.你要找到一个修改数最少的方案,得到我们所需要的素数. 例如把1033变到 ...
- Android tcpdump抓包应用实现
Android tcpdump抓包应用实现 Android应用很多时候都会涉及到网络,在请求网络出错时,我们可以通过抓包来分析网络请求,返回的数据等,通常我们是用tcpdump这个工具来抓包,再通 ...
- 根据浏览器UA信息进行跳转(移动和pc)
如何用php判断一个客户端是手机还是电脑?其实很简单,开发人员都知道,通过浏览器访问网站时,浏览器都会向服务器发送UA,即User Agent(用户代理).不同浏览器.同一浏览器的不同版本.手机浏览器 ...
- ural1019 Line Painting
Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109 ...
- Cow Rectangles
Cow Rectangles 题目描述 The locations of Farmer John's N cows (1 <= N <= 500) are described by dis ...
- CodeForces 614C Peter and Snow Blower
简单计算几何,只要算出圆心到多边形上的最短距离和最长距离即可 #include<cstdio> #include<cstring> #include<cmath> ...
- Angular2 - Starter - Routes, Route Resolver
在基于Angualr的SPA中,路由是一个很重要的部分,它帮助我们更方便的实现页面上区域的内容的动态加载,不同tab的切换,同时及时更新浏览器地址栏的URN,使浏览器回退和前进能导航到历史访问的页面. ...