Tony's Blog - 古人誠不我欺 - 2023年1月 https://www.iyiy.de/2023/01/ 係咁先,得閑飲茶! 记录下LNMP环境下使用CDN后获取访客真实IP的方法 https://www.iyiy.de/27.html 2023-01-29T13:38:00+08:00 获取访客真实IP在lnmp安装目录/root/lnmp下找到lnmp.conf并编辑Nginx_Modules_OptionsNginx_Modules_Options='--with-http_realip_module'保存后执行./upgrade.sh nginx升级下Nginx。找到网站配置文件,即/usr/local/nginx/conf/vhost/xx.com.conf并编辑。在任意一个location里加入以下参数:set_real_ip_from 添加CDN IP段 set_real_ip_from 0.0.0.0/0; real_ip_header X-Forwarded-For; real_ip_recursive on;CloudFlare IP段#Cloudflare set_real_ip_from 173.245.48.0/20; set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 108.162.192.0/18; set_real_ip_from 190.93.240.0/20; set_real_ip_from 188.114.96.0/20; set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; set_real_ip_from 162.158.0.0/15; set_real_ip_from 104.16.0.0/13; set_real_ip_from 104.24.0.0/14; set_real_ip_from 172.64.0.0/13; set_real_ip_from 131.0.72.0/22; set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; set_real_ip_from 2405:8100::/32; set_real_ip_from 2a06:98c0::/29; set_real_ip_from 2c0f:f248::/32; # use any of the following two #real_ip_header CF-Connecting-IP; real_ip_header X-Forwarded-For; real_ip_recursive on;编辑伪静态文件 直接插入 自动引用到所有vhost config上/usr/local/nginx/conf/rewrite/none.conf反向代理配置 location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; }关闭防跨站sed -i 's/^fastcgi_param PHP_ADMIN_VALUE/#fastcgi_param PHP_ADMIN_VALUE/g' /usr/local/nginx/conf/fastcgi.conf启用被禁用的函数sed -i 's/,system//g' /usr/local/php/etc/php.ini sed -i 's/,proc_open//g' /usr/local/php/etc/php.ini sed -i 's/,proc_get_status//g' /usr/local/php/etc/php.ini