Xenforo使用NGINX反向代理以及访客的真实IP设置

Posted by

查看phpinfo,看一下PHP版本中使用的真实IP变量,xenforo查看PHPINFO,进入后台:

admin.php?tools/phpinfo

查找可能的两个变量:$_SERVER[‘HTTP_X_FORWARDED_FOR’],也可能是:$_SERVER[‘HTTP_X_REAL_IP’]
编辑src/config.php
加入:


if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}

如果使用CloudFlare免费的CDN,添加:


if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

我的XENFORO的站点CONF文件反代理设置是:


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;
client_max_body_size    35m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffer_size   16k;
proxy_buffers       32   16k;
proxy_busy_buffers_size 64k;
server {
    listen       80;
    server_name  www.****.com;
    charset utf-8;
    access_log off;
    error_log off;
   location / {
        proxy_pass  https://www.****.com:80;
		}	
}

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用 * 标注