nginx error: (99: Cannot assign requested address) nginx error: (99: Cannot assign requested address) nginx nginx

nginx error: (99: Cannot assign requested address)


With Amazon EC2 and elastic IPs, the server doesn't actually know its IP as with most any other server.

So you need to tell your linux to allow processes to bind to the non-local address. Just add the following line into /etc/sysctl.conf file:

# allow processes to bind to the non-local address# (necessary for apache/nginx in Amazon EC2)net.ipv4.ip_nonlocal_bind = 1

and then reload your sysctl.conf by:

$ sysctl -p /etc/sysctl.conf

which will be fine on reboots.


To avoid hard-coding the IP address in the config, do this:

listen *:80;listen [::]:80;


As kirpit mentioned above you'll want to allow linux processes to bind to a local IP address:

nano /etc/sysctl.conf# allow processes to bind to the non-local addressnet.ipv4.ip_nonlocal_bind = 1sysctl -p /etc/sysctl.conf

Then you want to add the private ip address that is associated with your elastic ip and add that to your sites config:

nano /etc/nginx/sites-available/example.com

Reload nginx:

service nginx reload

All done!