I have searched and looked at many answers and solutions on StackOverflow and none of them have helped me fix my issue.
For the record, I am running Laravel framework on Laravel forge, which runs on Nginx.
My application has an admin user functionality which is activated by AJAX and might take 20-30 mins to complete. I mainly need to do these while the application is still new and then probably won't use it much in the future, so I just need to make it work for now at least.
So first I was getting Error 504 such as this:
2017/10/30 18:17:21 [error] 3603#3603: *89720 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 172.68.58.80, server: www.xxxxx.com, request: "POST /api/copy-table HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock", host: "www.xxxxx.com", referrer: "https://www.xxxxx.com/copy"
Then I adjusted these PHP values:
max_execution_time = 1800
output_buffering = 65535
As well as these Nginx values:
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 1800;
fastcgi_send_timeout 1800;
fastcgi_read_timeout 1800;
And now I am getting an Error 502 with this in the log:
2017/10/31 15:11:40 [error] 10795#10795: *3 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.68.58.80, server: www.xxxxx.com, request: "POST /api/copy-table HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "www.xxxxx.com", referrer: "https://www.xxxxx.com/copy"
This works great on my dev machine which is using Apache instead of Nginx, so it's definitely something with Nginx/PHP configuration that's causing this. I am also running Cloudflare on the live website, so I don't know if that could have any impact too?
Does anyone have any ideas what I can try next to fix this issue?