How to extract IP Address in Spring MVC Controller get call?

后端 未结 9 561
长发绾君心
长发绾君心 2020-11-28 04:04

I am working on Spring MVC controller project in which I am making a GET URL call from the browser -

Below is the url by which I am making a GET call from the browse

9条回答
  •  生来不讨喜
    2020-11-28 04:52

    In my case, I was using Nginx in front of my application with the following configuration:

    location / {
         proxy_pass        http://localhost:8080/;
         proxy_set_header  X-Real-IP $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header  Host $http_host;
         add_header Content-Security-Policy 'upgrade-insecure-requests';
    }
    

    so in my application I get the real user ip like so:

    String clientIP = request.getHeader("X-Real-IP");
    

提交回复
热议问题