Skip to content

绑定公网 IP / 弹性公网 IP

登录实例

绑定公网 IP 后即可远程连接云服务器。

阿里云阿里云


环境准备

在实例上安装 Nginx:

阿里云

bash
# 安装并启动 Nginx
apt update
apt -y install nginx

接入流程

开启 WAF(Web 应用防火墙)

阿里云


配置 DNS 解析接入

在阿里云解析中添加 WAF 接入 CNAME:

阿里云

修改 DNS 记录:

阿里云

检测 DNS:

阿里云


效果测试

修改 Nginx access.log 日志格式,输出 WAF 字段

查看配置:

bash
egrep -v '^$|#' /etc/nginx/nginx.conf

配置内容(节选):

nginx
http {
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"'
                    '"$http_waf"  "$http_lidao"';

    access_log /var/log/nginx/access.log main;
    ...
}

查看访问日志:

bash
cat /var/log/nginx/access.log

输出示例:

114.215.255.206 - - [07/Apr/2025:14:45:24 +0800] "GET / HTTP/1.1" 200 612 "-" "curl/7.81.0" "-""waf_test"  "lidao_test"
121.40.17.37    - - [07/Apr/2025:14:45:54 +0800] "GET / HTTP/1.1" 200 612 "-" "curl/7.81.0" "-""waf_test"  "lidao_test"

检查 DNS 解析

bash
nslookup www.linuxpath.cn

输出示例:

Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
www.linuxpath.cn        canonical name = www.linuxpath.cn.c.yundunwaf4.com.
Name:   www.linuxpath.cn.c.yundunwaf4.com
Address: 8.139.55.97

WAF 防护规则配置

设置白名单

阿里云

设置自定义规则

阿里云


浏览器访问测试

使用 Edge 浏览器访问测试页面:

阿里云

感谢阅读,欢迎交流!