Skip to content

Commit 89f78bd

Browse files
authored
添加nginx防止爬虫爬取配置 (Chanzhaoyu#1187)
* 添加nginx防止爬虫爬取配置 * Update nginx.conf * Update README.md
1 parent d598dc6 commit 89f78bd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [Docker 参数示例](#docker-参数示例)
2525
- [Docker build \& Run](#docker-build--run)
2626
- [Docker compose](#docker-compose)
27+
- [防止爬虫抓取](#防止爬虫抓取)
2728
- [使用 Railway 部署](#使用-railway-部署)
2829
- [Railway 环境变量](#railway-环境变量)
2930
- [手动打包](#手动打包)
@@ -234,6 +235,21 @@ services:
234235
```
235236
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
236237
- `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用
238+
239+
#### 防止爬虫抓取
240+
241+
**nginx**
242+
243+
将下面配置填入nginx配置文件中,可以参考 `docker-compose/nginx/nginx.conf` 文件中添加反爬虫的方法
244+
245+
```
246+
# 防止爬虫抓取
247+
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")
248+
{
249+
return 403;
250+
}
251+
```
252+
237253
### 使用 Railway 部署
238254
239255
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc)

docker-compose/nginx/nginx.conf

+7
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+
{
10+
return 403;
11+
}
12+
613
location / {
714
root /usr/share/nginx/html;
815
try_files $uri /index.html;

0 commit comments

Comments
 (0)