Skip to content

Commit 56c67f0

Browse files
author
Kerwin
committed
chore: nginx防止爬虫爬取配置
1 parent 5aaaf41 commit 56c67f0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [Docker 参数示例](#docker-参数示例)
4949
- [Docker build \& Run](#docker-build--run)
5050
- [Docker compose](#docker-compose)
51+
- [防止爬虫抓取](#防止爬虫抓取)
5152
- [使用 Railway 部署](#使用-railway-部署)
5253
- [Railway 环境变量](#railway-环境变量)
5354
- [手动打包](#手动打包)
@@ -311,6 +312,20 @@ volumes:
311312
```
312313
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
313314
- `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用
315+
316+
#### 防止爬虫抓取
317+
318+
**nginx**
319+
320+
将下面配置填入nginx配置文件中,可以参考 `docker-compose/nginx/nginx.conf` 文件中添加反爬虫的方法
321+
322+
```
323+
# 防止爬虫抓取
324+
if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot"){
325+
return 403;
326+
}
327+
```
328+
314329
### 使用 Railway 部署
315330
316331
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc)

docker-compose/nginx/nginx.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ server {
33
server_name localhost;
44
charset utf-8;
55
error_page 500 502 503 504 /50x.html;
6+
7+
# 防止爬虫抓取
8+
if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot"){
9+
return 403;
10+
}
11+
12+
613
location / {
714
root /usr/share/nginx/html;
815
try_files $uri /index.html;

0 commit comments

Comments
 (0)