3

I hosted a JavaScript file on my server running Wordpress on Nginx. I removed the file but there are still several requests from multiple referrers. These referrers are from different URLs and IP addresses.

There are a LOT of requests and I want to block them cause it seems to affect my server's performance.

Is there a way that I can block these requests?

3 Answers 3

2

I imagine that you'll get a performance gain when you configure nginx explicitely that the location of old javascript is no longer valid, as nginx won't need to check the filesystem anymore, and when you send a 410 error it won't need to send the 404 error page either:

location /path/to/script.js {
return 410 ; 
}

HTTP status code 410: Gone

The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is cacheable unless indicated otherwise.

The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient that the resource is intentionally unavailable and that the server owners desire that remote links to that resource be removed. Such an event is common for limited-time, promotional services and for resources belonging to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server owner.

2
  • I added this directive but it's still giving off a 404 instead of a 401. I'm accepting this as the answer as this lead me to a better direction. Thanks! Dec 19, 2013 at 16:11
  • You could use an error 404 "404 file not found" ; to send a simple message, straight from memory instead of the more userfriendly error_file you may have had configured elsewhere. Cheers!
    – HBruijn
    Dec 19, 2013 at 16:19
3
location = /deleted.js {
    default_type    text/plain;
    return      410 "410";
    #access_log off;
}

You might either want to disable the access log as above, or, if you're running a new enough nginx, configure access_log to do buffering. Disc access is generally very expensive, and is likely what's slowing you down.

BTW, using return automatically implies log_not_found off;, so, it's already better than simply leaving it to vfs to have the 404 generated.

1
  • I turned off the access_log as you said, disc writes are costly. Thanks. If I can upvote this I would. Dec 20, 2013 at 7:28
2

This is an idea using iptable's string module to check the http header content, of course it must be adapted to your special case: http://spamcleaner.org/en/misc/w00tw00t.html

However I'm not really sure about what would be faster between inspecting all of the incoming packets and having your webserver handle them. I'd eventually instead just add a line in the server configuration to immediately return a 404 on that specific url; traffic will self decrease with time, as webmasters and search engines correct their links (and they will, as 404 errors would cause a bad positioning in modern web search engines).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .