Loading... # 使用 阿里云CDN 后如何获取Nginx服务的真实IP地址 * 本教程仅适用于阿里云CDN/全站加速系列产品 * 本教程基于宝塔面板 ## 概述 本文主要介绍使用阿里云CDN/全站加速后如何获取Nginx服务的真实IP地址。 ## 详细信息 Nginx服务使用阿里云CDN后,用户访问的IP地址不真实,怎样获取真实的IP地址。在Nginx服务的配置文件内location配置项添加如下内容,就可以获取到Nginx服务的真实IP地址。 ``` location / { proxy_pass http://vs_service; index index.html index.htm index.jsp index.shtml; proxy_redirect off; proxy_set_header Host $host; proxy_set_header Ali-CDN-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ``` 注: `Ali-CDN-Real-IP`是CDN回源时用于记录客户端真实IP地址的Header参数。 ## 图文教程 宝塔面板→网站→设置  将下面的配置写入并保存,注意要放在花括号以内! ``` location / { proxy_pass http://vs_service; index index.html index.htm index.jsp index.shtml; proxy_redirect off; proxy_set_header Host $host; proxy_set_header Ali-CDN-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ```  Last modification:July 27th, 2020 at 03:16 pm © 允许付费转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Pay by AliPay