我使用以下代码来检测用户是否在代理/vpn 后面:
function checkUser()
{
$proxy = null;
$check = null;
$proxy = ($_SERVER['HTTP_ACCEPT_ENCODING'] != 'gzip, deflate') ? true : false;
if(empty($_SERVER['HTTP_CONNECTION']) || strtolower($_SERVER['HTTP_CONNECTION']) != 'keep-alive' || $_SERVER['HTTP_CACHE_CONTROL'] != 'max-age=0')
{
$check = ($proxy === true) ? 'proxy' : 'vpn';
}
return $check;
}
$connection = checkUser();
switch($connection)
{
case 'proxy': $var = 'It seems you are behind Proxy.'; break;
case 'vpn': $var = 'It seems you are using VPN.'; break;
default: $var = 'No Proxy or VPN detected.'; break;
}
echo $var;
但是,它在我拥有的旧服务器上运行良好,但在新服务器上却不行。新服务器正在使用反向代理服务器 (nginx)。有人可以告诉我它是否与 nginx 有关,以及我应该在配置中调整什么。谢谢!
- - 编辑: - -
#user nginx;
worker_processes 4;
worker_rlimit_nofile 950000;
#error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
#pid /var/run/nginx.pid;
events {
worker_connections 45000;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 5;
#tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server_tokens off;
include /etc/nginx/conf.d/*.conf;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}