
要在 Xray 的配置中禁止访问特定的网站,可以通过添加相应的路由规则来实现。这些规则可以使用域名或 IP 地址进行过滤。下面是一个示例,修改后的配置文件包括了禁止访问成人网站的规则。
假设你想禁止访问一些已知的成人网站,我们可以使用域名进行过滤:
{ "api": { "services": [ "HandlerService", "LoggerService", "StatsService" ], "tag": "api" }, "inbounds": [ { "listen": "127.0.0.1", "port": 62789, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api" } ], "outbounds": [ { "protocol": "freedom", "settings": {} }, { "protocol": "blackhole", "settings": {}, "tag": "blocked" } ], "policy": { "system": { "statsInboundDownlink": true, "statsInboundUplink": true } }, "routing": { "rules": [ { "inboundTag": [ "api" ], "outboundTag": "api", "type": "field" }, { "ip": [ "geoip:private" ], "outboundTag": "blocked", "type": "field" }, { "outboundTag": "blocked", "protocol": [ "bittorrent" ], "type": "field" }, { "type": "field", "domain": [ "geosite:category-porn" ], "outboundTag": "blocked" } ] }, "stats": {}}
在这个配置文件中,我添加了一条新的路由规则,该规则使用 geosite
{ "type": "field", "domain": [ "example-porn-site.com", "another-porn-site.com" ], "outboundTag": "blocked"}
你可以将上述规则添加到 routing 部分的 rules 数组中。这样,访问这些域名时将会被阻止。请注意,geosite
以下是一份完整的配置
{ "api": { "services": [ "HandlerService", "LoggerService", "StatsService" ], "tag": "api" }, "inbounds": [ { "listen": "127.0.0.1", "port": 62789, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api" } ], "outbounds": [ { "protocol": "freedom", "settings": {} }, { "protocol": "blackhole", "settings": {}, "tag": "blocked" } ], "policy": { "system": { "statsInboundDownlink": true, "statsInboundUplink": true } }, "routing": { "rules": [ { "inboundTag": [ "api" ], "outboundTag": "api", "type": "field" }, { "ip": [ "geoip:private" ], "outboundTag": "blocked", "type": "field" }, { "outboundTag": "blocked", "protocol": [ "bittorrent" ], "type": "field" }, { "type": "field", "domain": [ "geosite:category-porn" ], "outboundTag": "blocked" } ] }, "stats": {}}
要手动添加一些域名到 Xray 的配置文件中,以阻止访问这些特定的网站,你可以将这些域名添加到 routing 部分的 rules 数组中。这里是一个包含手动添加域名的示例配置文件:
假设你想手动添加一些域名,例如 example-porn-site.com 和 another-porn-site.com。
在这个配置文件中,我在 routing 部分的 rules 数组中添加了一条新的规则,用于手动指定要阻止的域名。
找到配置文件中的 routing 部分。
在 rules 数组中添加新的规则对象。
例如:
{ "type": "field", "domain": [ "example-porn-site.com", "another-porn-site.com" ], "outboundTag": "blocked"}
自动按标签屏蔽: 使用 geosite
{ "type": "field", "domain": [ "geosite:category-porn" ], "outboundTag": "blocked"}
手动添加域名屏蔽: 手动指定要屏蔽的特定域名。
{ "type": "field", "domain": [ "example-porn-site.com", "another-porn-site.com" ], "outboundTag": "blocked"}
这两条规则都可以添加到你的 routing 部分的 rules 数组中。以下是完整的配置文件示例:
{ "api": { "services": [ "HandlerService", "LoggerService", "StatsService" ], "tag": "api" }, "inbounds": [ { "listen": "127.0.0.1", "port": 62789, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api" } ], "outbounds": [ { "protocol": "freedom", "settings": {} }, { "protocol": "blackhole", "settings": {}, "tag": "blocked" } ], "policy": { "system": { "statsInboundDownlink": true, "statsInboundUplink": true } }, "routing": { "rules": [ { "inboundTag": [ "api" ], "outboundTag": "api", "type": "field" }, { "ip": [ "geoip:private" ], "outboundTag": "blocked", "type": "field" }, { "outboundTag": "blocked", "protocol": [ "bittorrent" ], "type": "field" }, { "type": "field", "domain": [ "geosite:category-porn" ], "outboundTag": "blocked" }, { "type": "field", "domain": [ "example-porn-site.com", "another-porn-site.com" ], "outboundTag": "blocked" } ] }, "stats": {}}
将这个配置文件保存到你的 Xray 配置文件(通常是 config.json)中即可。这样,配置文件既包含自动按标签屏蔽,也包含手动添加域名屏蔽的规则。