NGINX Прокси
Прокси файл для nginx
Прокси
server{
listen 80;
server_name domain.test;
location / {
proxy_pass http://172.20.0.25:80/;
include inc/proxy_params.inc;
}
}
Файл inc/proxy_params.inc
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Несколько NGINX прокси
Если стоит цепочка из нескольки NGINX серверов, то лучше сделать следующее:
В proxy_params указать следующее:
set $server_ip $server_addr;
set $the_http_x_forwarded_proto $scheme;
set $the_http_x_forwarded_for "${http_x_forwarded_for}, ${http_x_forwarded_ip}, ${server_ip}";
if ($http_x_forwarded_ip = ""){
set $the_http_x_forwarded_for "${http_x_forwarded_for}, ${server_ip}";
}
if ($http_x_forwarded_proto = "https"){
set $the_http_x_forwarded_proto "https";
}
if ($http_x_forwarded_for = ""){
set $the_http_x_forwarded_for "$proxy_add_x_forwarded_for, ${server_ip}";
}
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $the_http_x_forwarded_for;
proxy_set_header X-Forwarded-IP $server_ip;
proxy_set_header X-Forwarded-Proto $the_http_x_forwarded_proto;
#set_real_ip_from PROXY_IP1;
#set_real_ip_from PROXY_IP2;
#real_ip_header X-Real-IP;
#real_ip_recursive on;
#proxy_next_upstream error timeout http_502;