[英]nginx: how to get the actual client ip?
我有一个简单的快递应用程序。 这是Dockerized
。 这是存储库。
我在那里使用nginx
作为反向代理。 当我访问http://45.33.97.232:3000
时,它给了我实际的IP 。 但是,当我访问http://45.33.97.232/
时,它给了我相同的服务器IP 。 但我在这里需要实际Client IP
。 我在nginx
配置文件中使用服务器 IP 。 但我有一个限制,我不能在nginx
配置文件中写入服务器 IP 。
这是我的nginx
配置文件,
server {
listen 80 default_server;
server_name 45.33.97.232;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://45.33.97.232:3000; #port where you are serving your express app.
}
}
In nginx if you want to pass through the IP address of the remote user to your backend web server you have to set X-Forwarded-For header to this remote ip, Like this:
proxy_set_header X-Forwarded-For $remote_addr;
如果您不想使用服务器 IP,您可以使用 Nginx 配置文件中的域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.