男的舔女的下面视频在线播放-少妇愉情理仑片高潮日本-久久久久久国产一区二区三区-麻豆精品一区二区综合-国产精品超碰在线观看-网红极品女神精品视频在线-国产亚洲综合777-高清性视频一区二区播放-中文字幕第一页亚洲天堂

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

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

作者: zarro    時(shí)間: 2023-8-9 14:14
標(biāo)題: 關(guān)于x3.5版本獲取真實(shí)IP
升級(jí)了論壇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)端口,代理時(shí)需要添加這個(gè)東東;
  5.                                                 proxy_set_header X-REAL-IP $remote_addr;
  6.                                                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  7.                 }
復(fù)制代碼
4. 測(cè)試文件

  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ù)制代碼




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




歡迎光臨 Discuz! 官方交流社區(qū) (http://m.sdtechgong.com.cn/) Powered by Discuz! X5.0