套CloudFlare后,如何利用NGINX 获取用户真实IP?
在网上查到,在nginx.conf里面增加下面代码:set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
即可实现~原帖子地址:https://www.lizi.tw/program/6929.html
我之前用宝塔的时候有实验成功,转战军哥的lnmp后,添加上面代码报错。麻烦大佬们帮忙看一下~nginx重启报错信息:Stoping nginx... nginx: unknown directive "set_real_ip_from" in /usr/local/nginx/conf/nginx.conf:24
failed. Use force-quit
Terminating nginx...done
Starting nginx... nginx: unknown directive "set_real_ip_from" in /usr/local/nginx/conf/nginx.conf:24
failed
我的nginx配置添加位置userwww www;
worker_processes auto;
worker_cpu_affinity auto;
error_log/home/wwwlogs/nginx_error.logcrit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept off;
accept_mutex off;
}
http
{
include mime.types;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
default_typeapplication/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
sendfile_max_chunk 512k;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length5k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE \.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
access_log off;
找到了替代的方法,很实用~
https://bbs.vpser.net/thread-14350-1-1.html set_real_ip_from 是 --with-http_realip_module 添加这个参数到 lnmp.conf 中的 Nginx_Modules_Options 后面的引号里面,再升级一下nginx就会增加上这个模块
页:
[1]