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;



以下是网上查的常见错误列表:
http://www.360doc.com/content/12/1024/11/1073512_243439687.shtml

你可能感兴趣的:(总结)