Java에서 클라이언트 IP가 127.0.0.1 문제를 반환합니다.

Java 개발에서 request.getRemoteAddr은 클라이언트 IP를 얻는 데 사용되며 반환된 결과는 항상 127.0.0.1입니다. 그 이유는 서버가 nginx 리버스 프록시를 사용하기 때문입니다.

해결 방법: 추가: nginx 구성 파일 nginx.conf에 proxy_set_header X-Real-IP $remote_addr 

server {

    location ^~ /testweb/ {
        root   html;
        access_log on;
        index index.jsp;
        proxy_set_header X-Real-IP  $remote_addr;  //添加此项
        proxy_pass http://127.0.0.1:88/testweb/;        
    }

}

자바 코드는 다음과 같습니다.

ip2region은 IP를 구문 분석하여 지역 위치를 얻습니다.-CSDN 블로그

추천

출처blog.csdn.net/qq_26112725/article/details/134181511