Nginx Open Failed 11 Resource Temporarily Unavailable
How to Fix nginx open failed 11 Resource Temporarily Unavailable Error
If you are using nginx as your web server, you may encounter an error like this in your logs:
nginx open failed 11 resource temporarily unavailable
connect() to unix:/var/lib/php7.0-fpm/web3.sock failed (11: Resource temporarily unavailable) while connecting to upstream
This error means that nginx cannot connect to the upstream server, which is usually php-fpm, because the system has run out of resources. This can cause your website to display a 502 Bad Gateway error or become very slow.
In this article, we will explain what causes this error and how to fix it.
What causes nginx open failed 11 Resource Temporarily Unavailable Error?
This error can be caused by several factors, such as:
Too many open files: The system has a limit on how many files a process can open at the same time. If nginx or php-fpm reaches this limit, they cannot create new connections.
Too many processes: The system also has a limit on how many processes can run at the same time. If nginx or php-fpm spawns too many child processes, they may exhaust the available resources.
Too many requests: The system may not be able to handle a high volume of requests, especially if they are complex or slow. This can create a backlog of connections that nginx or php-fpm cannot process.
To find out which factor is causing the error, you can check the following:
The number of open files: You can use the command lsof wc -l to count how many files are open by all processes. You can also use lsof -p PID to count how many files are open by a specific process, where PID is the process ID of nginx or php-fpm.
The number of processes: You can use the command ps -ef wc -l to count how many processes are running on the system. You can also use ps -ef grep nginx or ps -ef grep php-fpm to count how many processes are running by nginx or php-fpm.
The number of requests: You can use the command netstat -an grep ESTABLISHED wc -l to count how many established connections are on the system. You can also use netstat -an grep ESTABLISHED grep :80 or netstat -an grep ESTABLISHED grep :443 to count how many established connections are on port 80 or 443, which are usually used by nginx.
How to fix nginx open failed 11 Resource Temporarily Unavailable Error?
To fix this error, you need to increase the system resources available for nginx and php-fpm. There are several ways to do this, such as:
Increase the limit of open files: You can edit the file /etc/security/limits.conf and add the following lines:
* soft nofile 65536
* hard nofile 65536
www-data soft nofile 65536
www-data hard nofile 65536
This will increase the limit of open files for all users and for the www-data user, which is usually used by nginx and php-fpm. You need to restart your system for the changes to take effect.
Increase the limit of processes: You can edit the file /etc/sysctl.conf and add the following line:
kernel.pid_max = 65536
This will increase the limit of processes for the system. You need to run sysctl -p for the changes to take effect.
Increase the limit of requests: You can edit the configuration files of nginx and php-fpm and adjust the following parameters:
# For nginx
worker_processes auto; # Adjusts the number of worker processes based on CPU cores
worker_connections 1024; # Adjusts the number of connections per worker process
keepalive_timeout 65; # Adjusts the timeout for keep-alive connections
# For php-fpm
pm = dynamic # Adjusts the number of child processes based on demand
pm.max_children = 20 # Adjusts the maximum number of child processes
pm.start_servers = 2 # Adjusts the number of child processes created at startup
pm.min_spare_servers = 1 # Adjusts the minimum number of idle child processes
pm.max_spare_servers = 3 # Adjusts the maximum number of idle child processes
pm.max_requests = 1024 # Adjusts the number of requests per child process before recycling
You need to reload nginx and php-fpm for the changes to take effect.
In this article, we have explained what causes nginx open failed 11 Resource Temporarily Unavailable Error and how to fix it. We hope this article has helped you solve your problem and improve your website performance.
In this article, we have explained what causes nginx open failed 11 Resource Temporarily Unavailable Error and how to fix it. We hope this article has helped you solve your problem and improve your website performance. d282676c82