nginx问题记录
2017-01-09 15:06
609 查看
工作中遇到几个关于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
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
相关文章推荐
- 记录nginx两种问题解决
- Ubuntu上安装nginx步骤及问题记录
- mac 上配置nginx过程中的问题记录
- 解决nginx在记录post数据时 中文字符转成16进制的问题【转载】
- Nginx安装配置问题记录
- nginx日志问题解决方法记录
- nginx线上问题记录
- centos7下nginx+uwsgi部署django项目问题记录
- Vue路由history模式踩坑记录:nginx配置解决404问题
- 【???】nginx_lua问题记录
- windows下的php、nginx、mysql配置记录和问题汇总
- 遇到了nginx 在win2008 下启动不了的问题,记录一下解决的方法
- CentOS 6.9环境下配置Nginx,Python,Mysql,Java,Redis环境及问题记录
- nginx配置反向代理或跳转出现400问题处理记录
- nginx重启问题处理记录
- nginx使用问题记录
- Nginx反向代理Odoo后导致日志中Werkzeug记录的IP地址不正确的问题
- [ Nginx ] 记录关于 $_GET 获取参数有误的一次问题排查
- 记录一次解决PHP返回数据被nginx截断的问题
- nginx的upstream问题记录