How to bulk delete unattached images from WordPress site

If you see the following error while deleting images in bulk in WordPress :
“Error 503 Service Unavailable

Service Unavailable

Guru Meditation:

XID: 000000000

Varnish cache server”

Step 1. First step would be to Increase the Nginx Buffers :
Open the nginx.conf file

 vi /etc/nginx/nginx.conf 

or

 vi /usr/local/nginx/conf/nginx.conf

and update(or add if not present already) to http or server or location context :

 set client body size to 2M 
client_max_body_size 2M; 

and

 set client body buffer size to 512K
client_body_buffer_size  512K;

Step 2. Now open the nginx master file :

 vi /etc/nginx/sites-available/master

or

 vi /usr/local/nginx/sites-available/master

Add these lines just after the server block :

client_header_buffer_size 32k;
large_client_header_buffers 16 512k;

Step 3. Apart from these settings, there has also been a known issue with the PHP Security Plugin. This plugins limits the maximum length allowed for a URL.
This affects bulk deleting as WordPress sends a URL with GET request with the ids of all the media to be deleted, so if someone is deleting more than 100 images at one time, the URL passed would be a very large one.

Now restart Nginx and test

 service nginx restart