添加nginx配置文件,解决nginx代理后无法获取客户端真实IP的问题
This commit is contained in:
@@ -8,6 +8,7 @@ import com.fjy.spring.service.AdminService;
|
||||
import com.fjy.spring.service.LogService;
|
||||
import com.fjy.spring.service.UserService;
|
||||
import com.fjy.spring.untils.CodingUtil;
|
||||
import com.fjy.spring.untils.GetIPAddrUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -57,7 +58,9 @@ public class LoginController {
|
||||
log.setUserid(user.getColuserid());
|
||||
log.setColtime(dateNowStr);
|
||||
log.setColheader(request.getHeader("user-agent"));
|
||||
log.setColip(request.getRemoteAddr());
|
||||
//解决nginx代理后IP地址获取问题
|
||||
//log.setColip(request.getRemoteAddr());
|
||||
log.setColip(GetIPAddrUtil.getIpAddr(request));
|
||||
logService.addLogRec(log);
|
||||
|
||||
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.fjy.spring.interceptor;
|
||||
|
||||
import com.fjy.spring.constant.GlobalConstant;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
22
src/main/java/com/fjy/spring/untils/GetIPAddrUtil.java
Normal file
22
src/main/java/com/fjy/spring/untils/GetIPAddrUtil.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.fjy.spring.untils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class GetIPAddrUtil {
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Real-IP");
|
||||
if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader(" Proxy-Client-IP ");
|
||||
//System.out.println("【Proxy-Client-IP】");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader(" WL-Proxy-Client-IP ");
|
||||
//System.out.println("【WL-Proxy-Client-IP】");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
//System.out.println("【unknown】");
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
src: url('../fonts/element-icons.ttf'),
|
||||
url('../fonts/element-icons.woff'); /* IE9 */
|
||||
}
|
||||
*{padding:0;margin:0;}
|
||||
html{height:100%;}
|
||||
body{min-height:100%;}
|
||||
.loginTitle{
|
||||
@@ -60,7 +59,6 @@ a{
|
||||
.footer{
|
||||
width:100%;
|
||||
font-size:14px;
|
||||
position:absolute;
|
||||
bottom:20px;
|
||||
left:0;
|
||||
text-align: center;
|
||||
|
||||
@@ -108,9 +108,8 @@
|
||||
|
||||
<el-footer th:fragment="footer">
|
||||
<div class="footer">
|
||||
© 2018 作业提交系统
|
||||
<br>
|
||||
<a href="http://gdcainfo.miitbeian.gov.cn/">©fjy8018.xin 粤ICP备18026008号 粤ICP备18026008号-1 </a>
|
||||
Copyright © 2018 作业提交系统 All Rights Reserved|
|
||||
<a href="http://www.miitbeian.gov.cn/">粤ICP备18026008号</a> 粤ICP备18026008号-1
|
||||
</div>
|
||||
</el-footer>
|
||||
</body>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<li>具备完整开发和维护文档,提供错误码、数据字典</li>
|
||||
<li>URL为RESTful API风格,便于开发和维护</li>
|
||||
<li>异常统一管理</li>
|
||||
<li><a href="https://blog.fjy8018.top/index.php/archives/100/">更多</a></li>
|
||||
</ul>
|
||||
<br>
|
||||
<ul>
|
||||
|
||||
Reference in New Issue
Block a user