For anyone facing the same issue, here's the solution. Solved it by adding the following settings:
php-fpm's php.ini
max_execution_time = 240
upload_max_filesize = 32M
post_max_size = 32M
php-fpm's pool configuration
request_terminate_timeout = 240s
request_slowlog_timeout = 230s
slowlog = /var/log/php5-fpm.slow.log
nginx.conf
client_header_timeout 240;
client_body_timeout 240;
fastcgi_read_timeout 240;
client_max_body_size 32m;
All thanks to this wonderful post