nginx+resin 后台如何获取客户端真实ip
公司有个小web项目,nginx做代理转发,nginx和resin部署同一机器上,现在需要获取客户真实ip, nginx.conf配置文件主要内容如下 (这个配置是正常的,nginx能够转发请求)
worker_processes 1;
events {
use epoll;
worker_connections 1024;
}
http {
upstream backend_vv {
server 127.0.0.1:88;
}
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
client_max_body_size 1024m;
keepalive_timeout 65;
server {
listen 80;
server_name zhishiku.51vv.com;
charset UTF-8;
access_log logs/access.log;
root /usr/local/resin/webapps/zhishiku;
index indexxx.html;
location / {
proxy_pass http://backend_vv/;
}
location ~ .(jsp|do|xtp|action|htm)$ {
proxy_pass http://backend_vv;
}
location /WEB-INF {
deny all;
}
location /logs {
deny all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
用java获取ip代码
request.getHeader("x-forwarded-for");request.getHeader("Proxy-Client-IP");
ipAddress = request.getHeader("WL-Proxy-Client-IP");ipAddress = request.getRemoteAddr();
获取的ip为127.0.0.1(nginx的本地ip),看了网上参考加了下内容如下
proxy_buffering on;
proxy_buffers 8 8k;
proxy_ignore_client_abort on;
proxy_connect_timeout 60;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
不过加上去之后,重启nginx,从access.log日志看到接收到请求,但是转发不到resin上去,现在不知道怎么办了,求助下!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自己顶下!!