---
title: Troubleshooting with Nginx
description: Nginx is a high performance HTTP Server, in other words it is a software that provides a webserver. It is free and open source which works as a reverse proxy server. It is known for its simple configurations and can also be used for load balancing.
---

[![e-Zest logo\_An accion lab company\_Colour](https://blog.e-zest.com/hubfs/images/Logos%20with%20Tagline/Corporate/SVG/e-Zest%20logo_An%20accion%20lab%20company_Colour.svg "e-Zest logo_An accion lab company_Colour")](https://www.e-zest.com/)

- [WORK](https://www.e-zest.com/our-work)
- [SERVICES](https://www.e-zest.com/our-services) 
    - [Product Engineering](https://www.e-zest.com/digital-product-engineering-services)
    - [Enterprise Data Services](https://www.e-zest.com/enterprise-data-services)
    - [Digital Commerce](https://www.e-zest.com/digital-commerce-services)
    - [Digital Operations](https://www.e-zest.com/digital-operations)
    - [Digital Consulting](https://www.e-zest.com/digital-transformation-consulting-services)
    - [Digital Experience Design](https://www.e-zest.com/digital-experience-design)
- [INSIGHTS](https://blog.e-zest.com/)
- [CAREERS](https://www.e-zest.com/careers)
- [ENTERPRISE DATA SERVICES](https://www.e-zest.com/enterprise-data-services)
- [GENERATIVE AI](https://www.e-zest.com/generative-ai)
- [Healthcare](https://healthcare.e-zest.com)
- [Contact Us](https://www.e-zest.com/contact-us)

- ![Elevating Product Engineering with AI and ML](https://blog.e-zest.com/hubfs/Elevating%20Product%20Engineering%20with%20AI%20and%20ML.jpg)

  [BLOGS](https://blog.e-zest.com)
  
  #### Elevating Product Engineering with AI and ML

  As technology evolves and customer choices broaden, there is an increasing ...

  [Read more](https://blog.e-zest.com/elevating-product-engineering-with-ai-and-ml)
- ![e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024](https://blog.e-zest.com/hubfs/e-Zest%20%E2%80%93%20An%20Accion%20Labs%20Company%20-%20Gets%20Recognition%20as%20a%20Contender%20in%20the%20ISG%20Provider%20LensTM%20Study%20on%20Digital%20Engineering%20Services%202024.jpg)

  [NEWS](https://blog.e-zest.com/news)
  
  #### e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024

  We are delighted to announce that e-Zest – An Accion Labs Company has been ...

  [Read more](https://blog.e-zest.com/news/e-zest-an-accion-labs-company-gets-recognition-as-a-contender-in-the-isg-provider-lens-study-on-digital-engineering-services-2024)
- ![e-Zest Solutions supports Digital Pune Mission](https://blog.e-zest.com/hubfs/blog-files/Digital%20Literacy%20Bus%20e-Zest.png)

  [CSR](https://blog.e-zest.com/csr)
  
  #### e-Zest Solutions supports Digital Pune Mission

  **Pune, India:** e-Zest Solutions, a leading digital technology innovation ...

  [Read more](https://blog.e-zest.com/csr/e-zest-solutions-supports-digital-pune-mission)

- [Work](https://www.e-zest.com/our-work)
- [Services](https://www.e-zest.com/our-services)
- [Insights](https://blog.e-zest.com)
- [Careers](https://www.e-zest.com/careers)
- [Enterprise Data](https://www.e-zest.com/enterprise-data-services)
- [Generative AI](https://www.e-zest.com/generative-ai)
- [Innovations](https://www.e-zest.com/innovations)
- [Healthcare](https://healthcare.e-zest.com)
- [About](https://www.e-zest.com/about-us)
- [Contact](https://www.e-zest.com/contact-us)

- [Blog](https://blog.e-zest.com/)
- [News](https://blog.e-zest.com/news)
- [CSR](https://blog.e-zest.com/csr)

- [![Linkedin Icon](https://blog.e-zest.com/hubfs/icons/linkedin_icon_white.svg)](https://www.linkedin.com/company/e-zest-solutions/)
- [![Twitter Icon](https://blog.e-zest.com/hubfs/twitter-logo-silhouette%20(5).svg)](https://twitter.com/ezest)
- [![Facebook Icon](https://blog.e-zest.com/hubfs/facebook-app-logo%20(4).svg)](https://www.facebook.com/61259256638)
- [![Instagram Icon](https://blog.e-zest.com/hubfs/instagram-logo%20(4).svg)](https://www.instagram.com/ezestsolutions/)
- [![Youtube Icon](https://blog.e-zest.com/hubfs/icons/youtube_icon_white.svg)](https://www.youtube.com/user/ezestcorporate)

[![Go to top icon](https://blog.e-zest.com/hubfs/AA%20Assets/top%20button.svg)](https://blog.e-zest.com/troubleshooting-with-nginx#top)

Hit enter to search or ESC to close

Insights

e-Zest members share technology ideas to foster digital transformation.

- [Blog](https://blog.e-zest.com)
- [News](https://blog.e-zest.com/news)
- [Podcasts](https://www.e-zest.com/podcasts)
- [Healthcare](https://blog.e-zest.com/healthcare)
- [CSR](https://blog.e-zest.com/csr)
- [Whitepaper](https://blog.e-zest.com/whitepaper)
- [Playbook](https://blog.e-zest.com/playbook)
- [Media Kit](https://www.e-zest.com/media-kit)

# Troubleshooting with Nginx

[Anagha Thorat](https://blog.e-zest.com/author/anagha-thorat)  Nov 22, 2016

[Nginx](https://blog.e-zest.com/topic/nginx) [Troubleshooting with Nginx](https://blog.e-zest.com/topic/troubleshooting-with-nginx)

- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/troubleshooting-with-nginx&title=&summary=&source=>
- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/troubleshooting-with-nginx&text=Troubleshooting%20with%20Nginx>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/troubleshooting-with-nginx>
- <https://www.instagram.com/ezestsolutions/?u=https://blog.e-zest.com/troubleshooting-with-nginx>

- **Introduction**

What is Nginx?

Nginx is a high performance HTTP Server, in other words it is a software that provides a webserver. It is free and open source which works as a reverse proxy server. It is known for its simple configurations and can also be used for load balancing.

This document explains Nginx and configuration changes needed to be done as per errors.

It also explains error faced while configuring Nginx for load balancing and handling requests in a bulk and also provides solution to respective errors.

**Configurations of Nginx**

The configuration file is /etc/nginx/nginx.conf

- **Error 502 Bad Gateway:**

http {

...

fastcgi\_buffers 8 16k;

fastcgi\_buffer\_size 32k

fastcgi\_connect\_timeout 300;

fastcgi\_send\_timeout 300;

fastcgi\_read\_timeout 300;

...

}

- Increase buffer and timeouts inside http block in the nginx.conf file:
- Ensure your php-fpm service is listening according to what you have configured in nginx.

Edit www.conf file (in CentOS it is located at /etc/php-fpm.d/www.conf and try with one of the below two options:

listen = /var/run/php5-fpm.sock 

                    or

listen = 127.0.0.1:9000

service nginx restart

service php-fpm restart

After that, just restart the nginx and php-fpm service.

- **Error nginx errors “recv() failed (104: Connection reset by peer) while reading response header from upstream”**  
  Make the following changes in nginx.conf

proxy\_read\_timeout    1500s;

proxy\_send\_timeout    1500s;

proxy\_connect\_timeout 1500s;

send\_timeout         1500s;

proxy\_buffer\_size   128k;

proxy\_buffers   4 256k;

proxy\_busy\_buffers\_size   256k;

try\_files $uri $uri/ /index.php?$args; # make index.php handle requests for

access\_log on;

- Set the following parameters in nginx.conf file

fastcgi\_buffers 256 16k;

fastcgi\_buffer\_size 128k;

fastcgi\_busy\_buffers\_size 256k;

- Set the buffers and Buffer\_Size
- Increase the worker\_connections:

worker\_connections 20000;

- **To set the cache to max :**

Set

expires max;

**Error: Too many files open/Large Files Open**

If you are getting this error, it means you application has reached the maximum limit of open files. You need to increase open files limit.

To do so follow the following steps:

- Edit file /etc/sysctl.conf, enter:

vi /etc/sysctl.conf

- Append / modify the following line:

fs.file-max = 70000

- Save and close the file. Edit /etc/security/limits.conf, enter:

\# vi /etc/security/limits.conf

nginx       soft    nofile   10000

nginx       hard    nofile  30000

- Set soft and hard limit for all users or nginx user as follows:
- Save and close the file. Finally, reload the changes with sysctl command

\# sysctl –p

- nginx worker\_rlimit\_nofile Option (Increase Open FD Limit at Nginx Level)

vi /etc/nginx/nginx.conf

- set open fd limit to 30000

worker\_rlimit\_nofile 30000;

- Reload the nginx server

service nginx reload

- Final nginx.conf File

user nginx;

worker\_processes auto;

error\_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

 

#set open fd limit to 30000

worker\_rlimit\_nofile 30000;

 

events {

worker\_connections 20000;

}

 

http {

log\_format  main  '$remote\_addr - $remote\_user \[$time\_local\] "$request" '

'$status $body\_bytes\_sent "$http\_referer" '

'"$http\_user\_agent" "$http\_x\_forwarded\_for"';

 

access\_log  /var/log/nginx/access.log  main;

 

sendfile            on;

tcp\_nopush          on;

tcp\_nodelay         on;

keepalive\_timeout   65;

types\_hash\_max\_size 2048;

 

include             /etc/nginx/mime.types;

default\_type        application/octet-stream;

 

\# Load modular configuration files from the /etc/nginx/conf.d directory.

\# See http://nginx.org/en/docs/ngx\_core\_module.html#include

\# for more information.

include /etc/nginx/conf.d/\*.conf;

 

index   index.html index.htm;

 

server {

listen      8080;

\# listen       \[::\]:80 default\_server;

server\_name  localhost;

root         /usr/share/nginx/html;

#passenger\_enabled on;

\# Load configuration files for the default server block.

include /etc/nginx/default.d/\*.conf;

 

location / {

proxy\_pass  http://internal-test-ecom-internalelb-elb-936852263.us-west-2.elb.amazonaws.com;

proxy\_set\_header Host $http\_host;

\# proxy\_redirect off;

proxy\_buffer\_size   128k;

proxy\_buffers   4 256k;

proxy\_busy\_buffers\_size   256k;

proxy\_connect\_timeout       1500s;

proxy\_send\_timeout          1500s;

proxy\_read\_timeout          1500s;

send\_timeout                1500s;

expires max;

#proxy\_read\_timeout 150;

}

location ~ \\.(jpeg\\|jpg\\|gif\\|png\\|css\\|js\\|ico\\|swf)$ {

try\_files $uri $uri/ @proxy; # look for static files in root directory and ask backend if not successful

expires max;

access\_log off;

}

 

\# redirect server error pages to the static page /40x.html

\#

error\_page 404 /404.html;

#r\] 29880#0: \*737 upstream prematurely closed connection while reading response header from upstream

location = /40x.html {

}

 

\# redirect server error pages to the static page /50x.html

\#

error\_page 500 502 503 504 /50x.html;

location = /50x.html {

}

 

\# proxy the PHP scripts to Apache listening on 127.0.0.1:80

\#

#location ~ \\.php$ {

#    proxy\_pass   http://127.0.0.1;

#}

 

\# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

\#

location ~ \\.php$ {

#    root           html;

#expires max;

#    fastcgi\_pass   127.0.0.1:9000;

#    fastcgi\_index  index.php;

#    fastcgi\_param  SCRIPT\_FILENAME  /scripts$fastcgi\_script\_name;

 

fastcgi\_buffers 16 16k;

fastcgi\_buffer\_size 32k;

fastcgi\_read\_timeout 1500s;

fastcgi\_ignore\_client\_abort on;

#    include        fastcgi\_params;

}

 

\# deny access to .htaccess files, if Apache's document root

\# concurs with nginx's one

\#

#location ~ /\\.ht {

#    deny  all;

#}

}

}

- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/troubleshooting-with-nginx&text=Troubleshooting%20with%20Nginx>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/troubleshooting-with-nginx>
- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/troubleshooting-with-nginx&title=&summary=&source=>

### Similar Blog

[![Apache vs Nginx](https://blog.e-zest.com/hubfs/apache-vs-ngnix.png) Apache vs Nginx Today, the two most amazing open source servers, Apache HTTP and Nginx are ruling the internet world. Apache being the oldest is ... By Prasannasingh Bayas Oct 18, 2016](https://blog.e-zest.com/apache-vs-nginx)

[![How to enable SMS alerts in Nagios using AWS SNS](https://blog.e-zest.com/hubfs/blog-files/nagios.png) How to enable SMS alerts in Nagios using AWS SNS Nagios is a powerful management and monitoring system. It helps in identifying the IT infrastructure problems. It also helps in ... By Anagha Thorat Feb 06, 2019](https://blog.e-zest.com/how-to-enable-sms-alerts-in-nagios-using-aws-sns)

[![Installing and setting HDFS cluster through Ambari](https://blog.e-zest.com/hubfs/blog-files/Installing%20and%20setting%20HDFS%20cluster%20through%20Ambari-181205.png) Installing and setting HDFS cluster through Ambari Apache Ambari is an open source management tool/platform for managing, provisioning, securing and monitoring the Hadoop Cluster. ... By Anagha Thorat Oct 31, 2018](https://blog.e-zest.com/installing-and-setting-hdfs-cluster-through-ambari)

[SSL Encryption using Let’s Encrypt on AWS EC2 Amazon Linux **What is Let’s Encrypt:** By Anagha Thorat Feb 27, 2017](https://blog.e-zest.com/ssl-encryption-using-lets-encrypt-on-aws-ec2-amazon-linux)

## Helping Organizations Thrive in the Digital Age

[Contact Us](https://www.e-zest.com/contact-us)

- [About](https://www.e-zest.com/about-us)
- [Services](https://www.e-zest.com/our-services)
- [Work](https://www.e-zest.com/our-work)
- [Insights](https://blog.e-zest.com/)
- [Healthcare](https://healthcare.e-zest.com/)
- [Accion Labs](https://www.accionlabs.com/)

- <https://www.linkedin.com/company/e-zest-solutions/>
- <https://twitter.com/ezest>
- <https://www.facebook.com/eZest/>
- <https://www.instagram.com/ezestsolutions/>
- <https://www.youtube.com/user/ezestcorporate>

- Dallas
- Detroit
- Hannover
- Vienna
- London
- Pune

 © 2025 e-Zest Solutions

- [Privacy Policy](https://www.e-zest.com/privacypolicy)
- [Cookie Policy](https://www.e-zest.com/cookie-policy)

 Contact us

 Contact us

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.