This short post specifically targets:
– RoR as web development environment – Can be ignored as this is closely related to nginx configuration settings
– Nginx as web server
While working with ElasticBeanstalk environments, one of my requirement was to send a heavy job to Worker App that takes > 1 min (60 seconds) to complete and I had no configuration in place. The way beanstalk-app was handling that job was disappointing. That job never finishes within a minute and another job (duplicate) gets triggered by the app and this goes on till it reaches the max retry count.
I tried googling the solution and found that we have to increase the timeout for the web server which is handling the request. In my case it was `nginx`.
So I decided to write a config file under `.ebextensions/02_nginx_proxy.config` — I am not going into the details of `ebextensions` here as this is out of scope of this article.
Here’s how my config file looks like:
| client_max_body_size 30M; | |
| proxy_send_timeout 600; | |
| proxy_read_timeout 1h; | |
| send_timeout 600; | |
| upstream backend { | |
| server unix:///var/run/puma/my_app.sock ; | |
| } | |
| server { | |
| listen 80; | |
| access_log /var/log/nginx/access.log; | |
| error_log /var/log/nginx/error.log; | |
| server_name *.cmgresearch.net; | |
| large_client_header_buffers 8 32k; | |
| location / { | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header Host $http_host; | |
| proxy_set_header X-NginX-Proxy true; | |
| proxy_buffers 8 32k; | |
| proxy_buffer_size 64k; | |
| proxy_pass http://backend; | |
| proxy_redirect off; | |
| location /assets { | |
| root /var/app/current/public; | |
| } | |
| # enables WS support | |
| location /cable { | |
| proxy_pass http://backend; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade "websocket"; | |
| proxy_set_header Connection "Upgrade"; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| } | |
| } | |
| } |
Here if you focus on lines:
`proxy_send_timeout 600;`
`proxy_read_timeout 1h;`
`send_timeout 600;`
This will prevent sending multiple requests of same job type until the current one finishes in 1h.
If you need any inputs on what other lines are all about/doing, then leave your comment.
Happy Coding!

Leave a Reply