欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx反向代理后無法獲取客戶端真實IP地址

 更新時間:2023年03月06日 10:56:42   作者:Asurplus  
本文主要介紹了Nginx反向代理后無法獲取客戶端真實IP地址,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

當(dāng)我們使用 Nginx 代理轉(zhuǎn)發(fā)服務(wù)后,會發(fā)現(xiàn)我們無法獲取客戶端的真實IP地址,從而無法獲取客戶端的地理位置等信息。

1、原始配置文件如下

worker_processes ?1;

events {
? ? worker_connections ?1024;
}

http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;

? ? sendfile ? ? ? ?on;
?? ?
? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;

? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? }

? ? ? ? error_page ? 500 502 503 504 ?/50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root ? html;
? ? ? ? }
? ? }

}

2、配置轉(zhuǎn)發(fā)后

worker_processes ?1;

events {
? ? worker_connections ?1024;
}

http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;

? ? sendfile ? ? ? ?on;
?? ?
? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;

? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? }
? ? ? ??
? ? ? ? # 代理轉(zhuǎn)發(fā)
?? ??? ?location /api/{
?? ??? ??? ?proxy_set_header Host $http_host;
?? ??? ??? ?proxy_set_header X-Real-IP $remote_addr;
?? ??? ??? ?proxy_set_header REMOTE-HOST $remote_addr;
?? ??? ??? ?proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
?? ??? ??? ?proxy_set_header Public-Network-URL http://$http_host$request_uri;
?? ??? ??? ?proxy_pass http://localhost:8080/;
?? ??? ?}
?? ??? ?
? ? ? ? error_page ? 500 502 503 504 ?/50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root ? html;
? ? ? ? }
? ? }

}

這樣,我們就將客戶端的頭部信息一起轉(zhuǎn)發(fā)過去,就能獲取用戶的真實 IP 地址了

到此這篇關(guān)于Nginx反向代理后無法獲取客戶端真實IP地址的文章就介紹到這了,更多相關(guān)Nginx反向代理獲取IP地址內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論