PHP FPM timeout settings
To increase PHP timeout, you have to edit /etc/php/7.0/fpm/php.ini and change/add this:
max_execution_time = 300
For FPM you need to change /etc/php/7.0/fpm/pool.d/www.conf as well and change/add this:
php_admin_value[max_execution_time] = 300
There is also another option in the www.conf file names request_terminate_timeout, I didn't change that one because documentation says it should be used only the max_execution_time doesn't stop the script execution.
Next step, restart fpm:
service php7.0-fpm restart
nginx timeout settings
Edit your server configuration file, usually placed in /etc/nginx/sites-available/example.com, and in the cgi section add:
And then restart nginx:
service nginx reload
In case you are using nginx as a proxy to something else, you can find instructions in this article: How to Fix 504 Gateway Timeout using Nginx.