Nar
Nar

Reputation: 550

nginx error bind Cannot assign requested address

I am running Amazon Linux AMI and nginx and when I try starting my nginx server:

$ sudo /etc/init.d/nginx restart

I get the following error:

nginx: [emerg]: bind() to IP failed (99: Cannot assign requested address)

where "IP" is a placeholder for my IP address. Does anybody know why that error might be happening? This is running on EC2.

My nginx.conf file looks like this:

user              app;
worker_processes  4;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_types text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

  server_names_hash_bucket_size 64;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
  server {
        listen          IP:443; 
        server_name     name;
        include /etc/nginx/ssl.conf;
  }
}

kirpit say: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 and then reload your sysctl.conf.

But on Amazon Linux AMI bash: sysctl: command not found

Upvotes: 1

Views: 8875

Answers (1)

Chuan Ma
Chuan Ma

Reputation: 9914

Could you remove the IP part and just have this?

listen 443;

You only need to specify an IP if you have multiple IPs assigned to the server and you want nginx to listen to that IP only.

Upvotes: 6

Related Questions