当前位置:论坛首页 > Linux面板 > 讨论

宝塔面板Nginx下百度云CDN获得真实ip的办法

发表在 Linux面板2017-8-25 18:49 [复制链接] 2 7100

希望能进测试组,呵呵。。

看了网上的一些教程,小白自己摸索了一会,测试成功了。

优点:程序不需要改动,直接使用remote_addr即可获取IP地址
缺点:ip地址有可能被伪装,而且需要知道所有CDN节点的ip地址或者ip段


1、Nginx有个模块http_realip_module,用这个就可以获得真实的IP,默认都安装了。不行用这个看下。
  1. $ nginx -V
复制代码
2、在网站配置模块location 里头插入加上
  1. set_real_ip_from CDN的IP;
  2. real_ip_header X-Forwarded-For;
复制代码


下面是我配置好的IP的地址:
  1. set_real_ip_from 111.32.135.0/24;
  2. set_real_ip_from 111.32.136.0/24;
  3. set_real_ip_from 112.65.73.0/24;
  4. set_real_ip_from 112.65.74.0/24;
  5. set_real_ip_from 112.65.75.0/24;
  6. set_real_ip_from 119.84.92.0/24;
  7. set_real_ip_from 119.84.93.0/24;
  8. set_real_ip_from 113.207.100.0/24;
  9. set_real_ip_from 113.207.101.0/24;
  10. set_real_ip_from 113.207.102.0/24;
  11. set_real_ip_from 180.163.188.0/24;
  12. set_real_ip_from 180.163.189.0/24;
  13. set_real_ip_from 163.53.89.0/24;
  14. set_real_ip_from 101.227.206.0/24;
  15. set_real_ip_from 101.227.207.0/24;
  16. set_real_ip_from 119.188.97.0/24;
  17. set_real_ip_from 119.188.9.0/24;
  18. set_real_ip_from 61.155.149.0/24;
  19. set_real_ip_from 61.156.149.0/24;
  20. set_real_ip_from 61.155.165.0/24;
  21. set_real_ip_from 61.182.137.0/24;
  22. set_real_ip_from 61.182.136.0/24;
  23. set_real_ip_from 120.52.29.0/24;
  24. set_real_ip_from 120.52.113.0/24;
  25. set_real_ip_from 222.216.190.0/24;
  26. set_real_ip_from 219.159.84.0/24;
  27. set_real_ip_from 183.60.235.0/24;
  28. set_real_ip_from 116.31.126.0/24;
  29. set_real_ip_from 116.31.127.0/24;
  30. set_real_ip_from 117.34.13.0/24;
  31. set_real_ip_from 117.34.14.0/24;
  32. set_real_ip_from 42.236.93.0/24;
  33. set_real_ip_from 42.236.94.0/24;
  34. set_real_ip_from 119.167.246.0/24;
  35. set_real_ip_from 150.138.149.0/24;
  36. set_real_ip_from 150.138.150.0/24;
  37. set_real_ip_from 150.138.151.0/24;
  38. set_real_ip_from 117.27.149.0/24;
  39. set_real_ip_from 59.51.81.0/24;
  40. set_real_ip_from 220.170.185.0/24;
  41. set_real_ip_from 220.170.186.0/24;
  42. set_real_ip_from 183.61.236.0/24;
  43. set_real_ip_from 14.17.71.0/24;
  44. set_real_ip_from 124.95.168.0/24;
  45. set_real_ip_from 124.95.188.0/24;
  46. set_real_ip_from 61.54.46.0/24;
  47. set_real_ip_from 61.54.47.0/24;
  48. set_real_ip_from 101.71.55.0/24;
  49. set_real_ip_from 101.71.56.0/24;
  50. set_real_ip_from 183.232.51.0/24;
  51. set_real_ip_from 183.232.53.0/24;
  52. set_real_ip_from 157.255.25.0/24;
  53. set_real_ip_from 157.255.26.0/24;
  54. set_real_ip_from 182.150.0.0/24;
  55. set_real_ip_from 182.150.1.0/24;
  56. set_real_ip_from 112.25.90.0/24;
  57. set_real_ip_from 112.25.91.0/24;
  58. set_real_ip_from 58.211.2.0/24;
  59. set_real_ip_from 58.211.137.0/24;
  60. set_real_ip_from 122.190.2.0/24;
  61. set_real_ip_from 122.190.3.0/24;
  62. set_real_ip_from 119.84.92.0/24;
  63. set_real_ip_from 119.84.93.0/24;
  64. set_real_ip_from 113.207.100.0/24;
  65. set_real_ip_from 113.207.101.0/24;
  66. set_real_ip_from 113.207.102.0/24;
  67. set_real_ip_from 183.61.177.0/24;
  68. set_real_ip_from 183.61.190.0/24;
  69. set_real_ip_from 125.39.174.0/24;
  70. set_real_ip_from 125.39.239.0/24;
  71. set_real_ip_from 117.148.160.0/24;
  72. set_real_ip_from 117.148.161.0/24;
  73. set_real_ip_from 112.65.73.0/24;
  74. set_real_ip_from 112.65.74.0/24;
  75. set_real_ip_from 112.65.75.0/24;
  76. set_real_ip_from 115.231.186.0/24;
  77. set_real_ip_from 115.231.187.0/24;
  78. real_ip_header X-Forwarded-For;
复制代码


如果以后百度云IP有增加可以自己添加。最新百度云IP
https://ticket-baidu.kf5.com/posts/view/148628/
使用道具 举报 只看该作者 回复
发表于 2017-8-25 20:17:38 | 显示全部楼层
我是选择直接改源代码
HTTP_X_FORWARDED_FOR
使用道具 举报 回复 支持 反对
发表于 2021-4-15 15:17:08 | 显示全部楼层
测试可以用  real_ip_header X-Forwarded-For; 和CF的不一样
使用道具 举报 回复 支持 反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

企业版年付运维跟进群

普通问题处理

论坛响应时间:72小时

问题处理方式:排队(仅解答)

工作时间:白班:9:00 - 18:00

紧急问题处理

论坛响应时间:10分钟

问题处理方式:1对1处理(优先)

工作时间:白班:9:00 - 18:00

工作时间:晚班:18:00 - 24:00

立即付费处理
快速回复 返回顶部 返回列表