「Linux/nginx/拒否」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行1: | 行1: | ||
| + | ==特定uaを拒否する== | ||
/etc/nginx/conf.d/hogehoge.conf | /etc/nginx/conf.d/hogehoge.conf | ||
server { | server { | ||
| 行11: | 行12: | ||
参考:https://blog.mitsuto.com/nginx-useragent-deny | 参考:https://blog.mitsuto.com/nginx-useragent-deny | ||
| + | |||
| + | ==特定ipを拒否する== | ||
| + | server { | ||
| + | listen 80; | ||
| + | server_name html.localhost; | ||
| + | location / { | ||
| + | deny 210.131.xx.xx; # よくわからんip | ||
| + | allow all; | ||
| + | root /var/www/html/public; | ||
| + | index index.html index.php; | ||
| + | } | ||
| + | } | ||
2019年2月6日 (水) 01:29時点における版
特定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
allow all;
root /var/www/html/public;
index index.html index.php;
}
}
