https://blog.csdn.net/broadview2006/article/details/54570943
- 網卡接口刪除IP命令:ip a delete 192.168.1.1/24 dev ens33(你的設備名稱);
- centos6.0啓動命令:service iptables start
- netstat -luntp | grep 800;查看端口
- 首先配置代理:
- - 第二臺虛擬機訪問日誌的格式:
- 第三臺虛擬機格式:
- 第四臺虛擬機格式:
- 結論:在默認情況下,下劃線忽略,所以改爲了’ - ';
- 下面是我後來在服務器上做的實驗。
location / {
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $http_add_x_forwarded_for;
proxy_pass http://129.204.225.131:81;
}
然後,根據打印的日誌,獲取到了我的真實IP。
- 根據上面,可以看到,http_x_forwarded_for還是爲空。猜想,可能http_add_x_forwarded_for
是空的,而根據官網,如果x_forwarded_for頭沒有出現在客戶端的請求頭裏面,那麼,這個變量的值就會等於remote_addr。 - 對日誌做修改,查看打印信息;
虛擬機2:
虛擬機3:
官網解釋:
Embedded Variables
The ngx_http_proxy_module module supports embedded variables that can be used to compose headers using the proxy_set_header directive:
$proxy_host
name and port of a proxied server as specified in the proxy_pass directive;
$proxy_port
port of a proxied server as specified in the proxy_pass directive, or the protocol’s default port;
$proxy_add_x_forwarded_for
the “X-Forwarded-For” client request header field with the $remote_addr variable appended to it, separated by a comma. If the “X-Forwarded-For” field is not present in the client request header, the $proxy_add_x_forwarded_for variable is equal to the $remote_addr variable.