久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

Discuz! 官方交流社區(qū)

標(biāo)題: 關(guān)于x3.5版本獲取真實(shí)IP [打印本頁]

作者: zarro    時間: 2023-8-9 14:14
標(biāo)題: 關(guān)于x3.5版本獲取真實(shí)IP
升級了論壇3.5版本,發(fā)現(xiàn)IP出現(xiàn)問題了;弄了兩天,才弄好;

論壇自身是apache + php 5.6 的配置;
前面還有nginx代理;
正確配置如下;
1. 放開安全限制,ip接收其他參數(shù)頭;
config/config_global.php

  1. $_config['security']['onlyremoteaddr'] = 0; //默認(rèn)為1,表示只接受remote addr參數(shù)頭;
復(fù)制代碼
2. 修改ip相關(guān)配置參數(shù);
  1. $_config['ipgetter']['setting'] = 'header';
  2. $_config['ipgetter']['header']['header'] = 'HTTP_X_REAL_IP';
復(fù)制代碼


3. nginx配置
  1.   location / {
  2.                         client_max_body_size 1000m;
  3.                         proxy_pass      http://10.1.9.5:8080;
  4.                         proxy_set_header Host $host:$server_port; //論壇非標(biāo)準(zhǔn)端口,代理時需要添加這個東東;
  5.                                                 proxy_set_header X-REAL-IP $remote_addr;
  6.                                                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  7.                 }
復(fù)制代碼
4. 測試文件

  1. <?php
  2. class ip_getter_header {
  3.     public static function get($s) {
  4.         if (empty($s['header'])) {
  5.             return $_SERVER['REMOTE_ADDR'];
  6.         }
  7.         $ip = isset($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $_SERVER['REMOTE_ADDR'];

  8.         return $ip;
  9.     }
  10. }

  11. foreach ($_SERVER as $key => $value) {
  12.     echo "$key: $value<br>";
  13. }

  14. $customHeader = 'aaaaa';
  15. $ip = ip_getter_header::get(['header' => $customHeader]);
  16. echo "<Br><Br>Client IP Address: " . $ip;

  17. $customHeader2 = 'HTTP_AAAAA';
  18. $ip2 = ip_getter_header::get(['header' => $customHeader2]);
  19. echo "<Br>Client IP Address2: " . $ip2;
  20. ?>
復(fù)制代碼




作者: 專家    時間: 2023-8-10 05:31
你既然會改Nginx了,何不直接在Apache上接收Nginx傳過來的ip呢?那樣效果更好,也不用配置Discuz了,還能保證服務(wù)器log里的ip也沒有錯。
另外如果要改Discuz,需要同時修改Discuz本體和UCenter(如果你用的不是獨(dú)立模式),方法詳見http://www.9999xn.com/thread-14866-1-1.html
作者: 專家    時間: 2023-8-10 05:32
上一條回復(fù)里的鏈接給錯了,是這個:http://www.9999xn.com/thread-15034-1-1.html
作者: zarro    時間: 2023-8-10 14:00
大神啊,我才搜索到你的帖子啊,NB!!!
之前搜索到的是1314那個人發(fā)的。 測試發(fā)現(xiàn)不對,因?yàn)槲也粫幊蹋瑳]了解過php,不知道變量會被替換。
再次請教一下apache如何接受nginx的傳參,是直接賦值嗎?還是咋地。通常做法都是把ip新頭一直傳下去,這個我知道。




歡迎光臨 Discuz! 官方交流社區(qū) (http://www.9999xn.com/) Powered by Discuz! W1.0