目录1、原始配置文件如下2、配置转发后当我们使用 Nginx 代理转发服务后,会发现我们无法获取客户端的真实IP地址,从而无法获取客户端的地理位置等信息。 1、原始配置文件如下 wo
当我们使用 Nginx 代理转发服务后,会发现我们无法获取客户端的真实IP地址,从而无法获取客户端的地理位置等信息。
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;
}
}
}
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;
}
# 代理转发
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;
}
}
}
这样,我们就将客户端的头部信息一起转发过去,就能获取用户的真实 IP 地址了
到此这篇关于Nginx反向代理后无法获取客户端真实IP地址的文章就介绍到这了,更多相关Nginx反向代理获取IP地址内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Nginx反向代理后无法获取客户端真实IP地址
本文链接: https://www.lsjlt.com/news/198639.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-13
2024-05-13
2024-05-11
2024-05-11
2024-05-10
2024-05-07
2024-04-30
2024-04-30
2024-04-30
2024-04-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0