Browse Source

correctly set remote addr from x-forwarded-for

dev
Adrian Malacoda 1 year ago
parent
commit
ada88102c6
1 changed files with 13 additions and 2 deletions
  1. 13
    2
      configuration/nginx.conf

+ 13
- 2
configuration/nginx.conf View File

@@ -53,8 +53,14 @@ http {
53 53
             fastcgi_pass unix:/var/run/php5-fpm.sock;
54 54
             fastcgi_index index.php;
55 55
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
56
-            fastcgi_param REMOTE_ADDR $http_x_real_ip;
57 56
             include fastcgi_params;
57
+
58
+            # https://stackoverflow.com/a/36451158
59
+            set $realip $remote_addr;
60
+            if ($http_x_forwarded_for ~ "^(\d+\.\d+\.\d+\.\d+)") {
61
+              set $realip $1;
62
+            }
63
+            fastcgi_param REMOTE_ADDR $realip;
58 64
         }
59 65
     }
60 66
 
@@ -84,8 +90,13 @@ http {
84 90
             fastcgi_pass unix:/var/run/php5-fpm.sock;
85 91
             fastcgi_index index.php;
86 92
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
87
-            fastcgi_param REMOTE_ADDR $http_x_real_ip;
88 93
             include fastcgi_params;
94
+
95
+            set $realip $remote_addr;
96
+            if ($http_x_forwarded_for ~ "^(\d+\.\d+\.\d+\.\d+)") {
97
+              set $realip $1;
98
+            }
99
+            fastcgi_param REMOTE_ADDR $realip;
89 100
         }
90 101
     }
91 102
 }

Loading…
Cancel
Save