记录下LNMP环境下使用CDN后获取访客真实IP的方法
侧边栏壁纸
  • 累计撰写 13 篇文章
  • 累计收到 0 条评论

记录下LNMP环境下使用CDN后获取访客真实IP的方法

Tony
2023-01-29 / 0 评论 / 220 阅读 / 正在检测是否收录...

在lnmp安装目录/root/lnmp下找到lnmp.conf并编辑Nginx_Modules_Options

Nginx_Modules_Options='--with-http_realip_module'

保存后执行./upgrade.sh nginx升级下Nginx。
找到网站配置文件,即/usr/local/nginx/conf/vhost/xx.com.conf并编辑。在任意一个location里加入以下参数:

    set_real_ip_from 0.0.0.0/0;
    real_ip_header X-Forwarded-For;

题外

proxy_pass代理配置

  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
0

评论

博主关闭了所有页面的评论