$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri
## Block http user agent - wget ##
if ($http_user_agent ~* (Wget|Curl) ) {
return 403;
}
## Block Software download user agents ##
if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
return 403;
}
if ($http_user_agent ~ (msnbot|scrapbot) ) {
return 403;
}
if ($http_user_agent ~ (Spider|Robot) ) {
return 403;
}
禁止非瀏覽器訪問
if ($http_user_agent ~ ^$) {
return 412;
}
測試是否生效
tail -f /var/log/nginx/www.mydomain.com.access.log
telnet 192.168.2.10 80
GET /index.html HTTP/1.0
Host: www.mydomain.com
location / {
root /www/mydomain.com/info.mydomain.com;
index index.html;
rewrite ^/$ http://www.mydomain.com/;
valid_referers none blocked *.mydomain.com;
if ($invalid_referer) {
return 403;
}
proxy_intercept_errors on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
if (!-f $request_filename) {
proxy_pass http://old.mydomain.com;
break;
}
}