Browse Source

fix forward

lushuncheng 6 years ago
parent
commit
db8ac8d56c
1 changed files with 48 additions and 16 deletions
  1. 48 16
      config/nginx/template/proxy.nginx.conf

+ 48 - 16
config/nginx/template/proxy.nginx.conf

@@ -7,6 +7,14 @@ server {
     if ($temp_request_id = "") {
         set $temp_request_id $request_id;
     }
+    set $temp_scheme $http_x_forwarded_proto;
+    if ($temp_scheme = "") {
+        set $temp_scheme $scheme;
+    }
+    set $temp_addr $http_x_forwarded_for;
+    if ($temp_addr = "") {
+        set $temp_addr $remote_addr;
+    }
     add_header 'X-Request-Id' "$temp_request_id";
     access_log /data/log/proginn-access.log proginn-logid;
 
@@ -23,10 +31,10 @@ server {
         limit_req zone=byip burst=100;
         proxy_pass http://{{ip}}/;
         proxy_set_header Host $http_host;
-        proxy_set_header X-Real-IP  $remote_addr;
-        proxy_set_header X-Forwarded-For $remote_addr;
-        proxy_set_header X-Forwarded-Proto $scheme;
-        proxy_set_header X-Scheme $scheme;
+        proxy_set_header X-Real-IP  $temp_addr;
+        proxy_set_header X-Forwarded-For $temp_addr;
+        proxy_set_header X-Forwarded-Proto $temp_scheme;
+        proxy_set_header X-Scheme $temp_scheme;
         proxy_set_header Origin $http_origin;
         proxy_set_header X-Request-Id $temp_request_id;
         proxy_http_version 1.1;
@@ -75,6 +83,14 @@ server {
     if ($temp_request_id = "") {
         set $temp_request_id $request_id;
     }
+    set $temp_scheme $http_x_forwarded_proto;
+    if ($temp_scheme = "") {
+        set $temp_scheme $scheme;
+    }
+    set $temp_addr $http_x_forwarded_for;
+    if ($temp_addr = "") {
+        set $temp_addr $remote_addr;
+    }
     add_header 'X-Request-Id' "$temp_request_id";
     access_log /data/log/rooter-access.log proginn-logid;
 
@@ -91,10 +107,10 @@ server {
         limit_req zone=byip burst=100;
         proxy_pass http://{{ip}}/;
         proxy_set_header Host $http_host;
-        proxy_set_header X-Real-IP  $remote_addr;
-        proxy_set_header X-Forwarded-For $remote_addr;
-        proxy_set_header X-Forwarded-Proto $scheme;
-        proxy_set_header X-Scheme $scheme;
+        proxy_set_header X-Real-IP  $temp_addr;
+        proxy_set_header X-Forwarded-For $temp_addr;
+        proxy_set_header X-Forwarded-Proto $temp_scheme;
+        proxy_set_header X-Scheme $temp_scheme;
         proxy_set_header Origin $http_origin;
         proxy_set_header X-Request-Id $temp_request_id;
         proxy_http_version 1.1;
@@ -142,6 +158,14 @@ server {
     if ($temp_request_id = "") {
         set $temp_request_id $request_id;
     }
+    set $temp_scheme $http_x_forwarded_proto;
+    if ($temp_scheme = "") {
+        set $temp_scheme $scheme;
+    }
+    set $temp_addr $http_x_forwarded_for;
+    if ($temp_addr = "") {
+        set $temp_addr $remote_addr;
+    }
     add_header 'X-Request-Id' "$temp_request_id";
     access_log /data/log/jishuin-access.log proginn-logid;
 
@@ -155,10 +179,10 @@ server {
         limit_req zone=byip burst=100;
         proxy_pass http://{{ip}}/;
         proxy_set_header Host $http_host;
-        proxy_set_header X-Real-IP  $remote_addr;
-        proxy_set_header X-Forwarded-For $remote_addr;
-        proxy_set_header X-Forwarded-Proto $scheme;
-        proxy_set_header X-Scheme $scheme;
+        proxy_set_header X-Real-IP  $temp_addr;
+        proxy_set_header X-Forwarded-For $temp_addr;
+        proxy_set_header X-Forwarded-Proto $temp_scheme;
+        proxy_set_header X-Scheme $temp_scheme;
         proxy_set_header Origin $http_origin;
         proxy_set_header X-Request-Id $temp_request_id;
         proxy_http_version 1.1;
@@ -206,6 +230,14 @@ server {
     if ($temp_request_id = "") {
         set $temp_request_id $request_id;
     }
+    set $temp_scheme $http_x_forwarded_proto;
+    if ($temp_scheme = "") {
+        set $temp_scheme $scheme;
+    }
+    set $temp_addr $http_x_forwarded_for;
+    if ($temp_addr = "") {
+        set $temp_addr $remote_addr;
+    }
     add_header 'X-Request-Id' "$temp_request_id";
     access_log /data/log/jishuin-access.log proginn-logid;
 
@@ -219,10 +251,10 @@ server {
         limit_req zone=byip burst=100;
         proxy_pass http://{{ip}}/;
         proxy_set_header Host $http_host;
-        proxy_set_header X-Real-IP  $remote_addr;
-        proxy_set_header X-Forwarded-For $remote_addr;
-        proxy_set_header X-Forwarded-Proto $scheme;
-        proxy_set_header X-Scheme $scheme;
+        proxy_set_header X-Real-IP  $temp_addr;
+        proxy_set_header X-Forwarded-For $temp_addr;
+        proxy_set_header X-Forwarded-Proto $temp_scheme;
+        proxy_set_header X-Scheme $temp_scheme;
         proxy_set_header Origin $http_origin;
         proxy_set_header X-Request-Id $temp_request_id;
         proxy_http_version 1.1;