fxmqs 2016-11-25 02:49 采纳率: 100%
浏览 5453
已采纳

nginx四层透明代理配置问题

nginx官网说明:
The transparent parameter (1.11.0) allows outgoing connections to a proxied server originate from a non-local IP address, for example, from a real IP address of a client:

proxy_bind $remote_addr transparent;
In order for this parameter to work, it is necessary to run nginx worker processes with the superuser privileges and configure kernel routing table to intercept network traffic from the proxied server.

目前调试发现,当客户端与nginx处于同一机器上时,透明代理转发功能是正常的,但是当客户端与nginx处于不同机器,那么nginx发送的syn不被代理机器响应,问题是:怎么配置内核路由才能实现透明转发?

  • 写回答

1条回答

  • fxmqs 2016-11-26 07:26
    关注

    查了一会,保证路由畅通的前提下,配置如下:
    iptables -t mangle -N DIVERT
    iptables -t mangle -A PREROUTING -p udp -m socket -j DIVERT
    iptables -t mangle -A DIVERT -j MARK --set-xmark 0x1/0xffffffff
    iptables -t mangle -A DIVERT -j ACCEPT
    iptables -t mangle -A PREROUTING -p tcp -s 10.0.0.0/24<被代理服务IP> --sport 8682<被代理服务端口> -j TPROXY --tproxy-mark 0x1/0x1 --on-port 0
    ip rule add fwmark 1 lookup 100
    ip route add local 0.0.0.0/0 dev lo table 100

    service iptables save
    service iptables restart

    详细资料见官方:https://www.nginx.com/blog/ip-transparency-direct-server-return-nginx-plus-transparent-proxy/?utm_source=ip-transparency-direct-server-return-nginx-plus-transparent-proxy&utm_medium=blog#ip-transparency

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序