I'm new to nginx server. The problem I'm facing currently is connection timed out issue after making a call from the iOS app. The Json I'm receiving is huge hence there is a timeout logged on the server.
Also checked with various answers posted here on stackoverflow regarding the same. But didn't help me out.
Below is my access log and error log. Please help.
Error log
upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxxxxxxxxx, server: xxxxxxxxxxx, request: "POST /api/event/gallery HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock", host: "xxxxxxxxxxx"
Access log
"POST /api/event/gallery HTTP/1.1" 504 192 "-" "mysite/2 CFNetwork/889.9 Darwin/16.7.0"
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 50M;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Nginx “upstream timeout (110: Connection timed out)” error appears when nginx is not able to receive an answer from the webserver. As a part of our Server Management Services, Our Support Engineers helps webmasters fix Nginx-related errors regularly.
The default timeout limit is 60 seconds for proxying requests from nginx to Apache.
Edit the specific server block configuration file and add the following settings: server{ ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... } After making the changes, you must restart the NGINX service to apply changes.
Update
While I was checking with this issue I increased the time setting -request_terminate_timeout
in the \etc\php\7.0\fpm\pool.d\www.conf and encountered the HTTP status code 499.
Access log
"POST /api/event/gallery HTTP/1.1" 499 0 "-" "mysite/2 CFNetwork/889.9 Darwin/16.7.0"
So i started to investigate this issue and found out that there is load balancer in place (AWS ELB), which has a time out setting in place that defaults to 60 sec. Referr https://www.cadence-labs.com/2017/07/fix-nginx-timeout-499-client-closed-request/.
After increasing the timeout over there (ELB) I managed to get the result in postman. But it turned out to be highly erratic. Meaning I would get a response once in 4-5 tries.
So I managed to add some settings in etc\nginx\sites-available\default Added below settings over there in every server and location blocks.
fastcgi_read_timeout 540;
proxy_connect_timeout 3000s;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
and restarted nginx.
This solved the issue. But I still think that the time taken by response is high and the performance is not at an acceptable level.
Also any recommendations/comments/suggestions to address this issue in a better way are most welcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With