「Linux/nginx/拒否」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「/etc/nginx/conf.d/hogehoge.conf server { listen 80; #default_server; if ( $http_user_agent ~* (SemrushBot|AhrefsBot) ) { return 403; } }」) |
|||
| (同じ利用者による、間の13版が非表示) | |||
| 行1: | 行1: | ||
| + | ==特定uaを拒否する== | ||
/etc/nginx/conf.d/hogehoge.conf | /etc/nginx/conf.d/hogehoge.conf | ||
server { | server { | ||
listen 80; #default_server; | listen 80; #default_server; | ||
if ( $http_user_agent ~* (SemrushBot|AhrefsBot) ) { | if ( $http_user_agent ~* (SemrushBot|AhrefsBot) ) { | ||
| + | #return 410; # Botの場合は410で再訪しないようにするのがよいかも。 | ||
return 403; | return 403; | ||
} | } | ||
} | } | ||
| + | |||
| + | 参考:https://parudou3.com/nginx/818/ | ||
| + | |||
| + | 参考:https://blog.mitsuto.com/nginx-useragent-deny | ||
| + | |||
| + | ==特定ipを拒否する== | ||
| + | server { | ||
| + | listen 80; | ||
| + | server_name html.localhost; | ||
| + | location / { | ||
| + | deny 210.131.xx.xx; #このipを拒否(xx部分は数字) | ||
| + | allow all; #他全ては許可 | ||
| + | root /var/www/html/public; | ||
| + | index index.html index.php; | ||
| + | } | ||
| + | } | ||
| + | 動作を確認した。 | ||
| + | ==特定ipを拒否する(範囲)== | ||
| + | <pre> | ||
| + | # 拒否するIP範囲(11.11.*.* と 22.22.*.*) | ||
| + | deny 11.11.0.0/16; | ||
| + | deny 22.22.0.0/16; | ||
| + | </pre> | ||
| + | |||
| + | ==拒否する特定ipを外だしする場合== | ||
| + | server { | ||
| + | listen 80; | ||
| + | server_name html.localhost; | ||
| + | location / { | ||
| + | include /etc/nginx/conf.d/hogehoge.ip; | ||
| + | root /var/www/html/public; | ||
| + | index index.html index.php; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /etc/nginx/conf.d/hogehoge.ip | ||
| + | deny 210.131.xx.xx; #このipを拒否 | ||
| + | allow all; #他全ては許可 | ||
2025年6月12日 (木) 00:26時点における最新版
特定uaを拒否する
/etc/nginx/conf.d/hogehoge.conf
server {
listen 80; #default_server;
if ( $http_user_agent ~* (SemrushBot|AhrefsBot) ) {
#return 410; # Botの場合は410で再訪しないようにするのがよいかも。
return 403;
}
}
参考:https://parudou3.com/nginx/818/
参考:https://blog.mitsuto.com/nginx-useragent-deny
特定ipを拒否する
server {
listen 80;
server_name html.localhost;
location / {
deny 210.131.xx.xx; #このipを拒否(xx部分は数字)
allow all; #他全ては許可
root /var/www/html/public;
index index.html index.php;
}
}
動作を確認した。
特定ipを拒否する(範囲)
# 拒否するIP範囲(11.11.*.* と 22.22.*.*) deny 11.11.0.0/16; deny 22.22.0.0/16;
拒否する特定ipを外だしする場合
server {
listen 80;
server_name html.localhost;
location / {
include /etc/nginx/conf.d/hogehoge.ip;
root /var/www/html/public;
index index.html index.php;
}
}
/etc/nginx/conf.d/hogehoge.ip
deny 210.131.xx.xx; #このipを拒否 allow all; #他全ては許可
