Troubleshooting NGINX

Starting nginx: [emerg] bind() to 1.2.3.4:80 failed (99: Cannot assign requested address)

If you're trying to start Nginx, but it throws this error:

Starting nginx: nginx: [emerg] bind() to 1.2.3.4:80 failed (99: Cannot assign requested address)    [FAILED]

it would likely mean that the IP in question does not exist in your device. Type the following to see which IPs are in your device:

ip a

If your network was restarted, the additional IPs should be started with:

service startips start

If, for whatever reason, the IPs cannot be loaded into the device but you must still have that IP in the Nginx config, then you can set:

net.ipv4.ip_nonlocal_bind = 1

into your /etc/sysctl.conf file, and reboot.

How to find which site is using the Nginx processes

If you're running Nginx with CustomBuild 2.0, then it's already in the file /etc/nginx/nginx-info.conf.

Change the "allow" lines to include your IP (eg: 1.2.3.4), OR remove the line completely to allow from all.

location /nginx_status {
   # Enable nginx status page
   stub_status on;

   # Disable status page logging in access_log
   access_log off;

   # Allow access from 127.0.0.1
   allow 1.2.3.4;

   # Deny all the other connections
   deny all;
}

OR

location /secret_nginx_status {
   # Enable nginx status page
   stub_status on;

   # Disable status page logging in access_log
   access_log off;
}

Change the /secret_server-status to something hard-to guess if you use the 2nd method, since we don't want just anyone viewing this page.

Note that the stats shown on this page are not terribly useful. They only show the number of connections, and a small handful of numbers.open in new window

The default Nginx installation does not show information on each connection like Apache does.

If needed, PHP-FPM has it's own status pageopen in new window, which is better than nothing if you're running Nginx.

502 bad gateway error when using Nginx with PHP-FPM

If you're getting an error similar to "502 bad gateway", try raising the maximum number of queued connections on a socket from the kernel side.

By default it is set to 128, so try increasing to 4096:

sysctl -w net.core.somaxconn=4096

The new value will not survive a reboot. If it worked well, make the change constant by editing the file /etc/sysctl.conf accordingly per the OS in use:

For Debian/CentOS:

net.core.somaxconn=4096

504 Gateway Time-Out error

If you're receiving the message "504 Gateway Time-Out", this often implies a PHP timeout.

This can usually be resolved by increasing the values for:

max_execution_time

in the php.ini, and

fastcgi_read_timeout

in /etc/nginx/nginx_limits.conf.

Restart PHP-FPM and Nginx after the change.

The default for fastcgi_read_timeout is 240 seconds (4 minutes).

Last Updated: