node.js - 防止通过ip地址访问
问题描述
使用 express.js 如何防止请求通过 ip 地址而不是通过 cloudflare 前面的域访问我的服务器?
这是为了防止 googlebot 索引http://xx.xx.xx.xxx/
解决方案
这就是我最终的结果,希望它有效。
app.get('/*', function(req, res, next) {
if (req.host === '129.8d.xx.xxx') {
res.redirect(301, 'https://example.com' + req.path)
}
else {
next();
}
})
推荐阅读
- javascript - 从列表中循环javascript
- python - 在列表的每个元素中计算数学
- c# - 为该记录选择最近的一行,按两列分组
- java - 加密/解密大文件时出现 java.lang.OutOfMemoryError
- java - 我怎样才能让我的模拟器按钮出现?
- sql-server - 连接SQL Server,服务器名问题
- java - 在特定 IP 地址的 Spring Boot 应用程序日志中隐藏 IllegalArgumentException
- docker - 在写入节点上创建“Kind”集群失败
- python - TypeError: get() 期望一个 dict 或 protobuf 消息,得到
- mysql - 返回选择匹配所在的 MySQL 列的名称