nginx问题记录

工作中遇到几个关于nginx的错误,总结如下,随用随记录
1、nginx获取不到真实客户端IP:
解决方法,在所有location中加入如下配置:
proxy_set_header x-forwarded-for $remote_addr;
对应在java中获取源ip的方法中按下述写法:
/**
 * 获取用户登录时本地的ip地址
 * @dup
 * @param request
 * @return
 */
public static String getRealIpAddres(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
2、连接超时:
错误现象:当程序要后台运行一个需要较长时间的方法时(通常超过60秒),nginx报如下错误:
2017/01/09 14:09:30 [error] 24696#0: *157 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.167.180.93, server: localhost, request: "POST /admincenter/manage/resourceauth/device/unix/unixaccount.do?method=unixExportSourcesAcc HTTP/1.1", upstream: "http://10.167.183.19:8091/admincenter/manage/resourceauth/device/unix/unixaccount.do?method=unixExportSourcesAcc", host: "10.167.183.109", referrer: "https://10.167.183.109/admincenter/manage/resourceauth/device/unix/unixTabPanel.jsp?resourceGroupRDN=cn=00550000000000000000&resourceGroupName=%25E9%25BE%2599%25E6%25B1%259F%25E6%25B5%258B%25E8%25AF%2595"
解决方法:在所有location中加入如下配置:
proxy_connect_timeout    600;
proxy_read_timeout       600;
proxy_send_timeout       600;



以下是网上查的常见错误列表:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值