nginx的错误:(99:无法分配请求的地址)分配、错误、地址、nginx

2023-09-11 08:39:09 作者:淫尸作乐

我运行Ubuntu Hardy的8.04和nginx的0.7.65,当我尝试启动我的nginx服务器:

  $ sudo的/etc/init.d/nginx开始
 

我收到以下错误:

 启动nginx的:[EMERG]:bind()将IP失败(99:无法分配请求的地址)
 

其中,IP是一个占位符,我的IP地址。有谁知道为什么这个错误可能发生?这是在EC2上运行。

我的nginx.conf中文件看起来是这样的:

 用户WWW的数据WWW的数据;
worker_processes 4;

事件{
    worker_connections 1024;
}

HTTP {
    包括的mime.types;
    default_type文件的应用程序/八位字节流;

    访问日志/usr/local/nginx/logs/access.log;

    SENDFILE上;
    tcp_nopush上;
    TCP_NODELAY上;

    keepalive_timeout 3;

    gzip压缩的;
    gzip_comp_level 2;
    gzip_proxied任;
    gzip_types文/明文/ CSS应用程序/ x-j​​avascript的文/ XML应用程序/ XML
    应用程序/ XML + RSS文/ JavaScript的;

    包括在/ usr /本地/ nginx的/站点启用/ *;

}
 
tomcat nginx配置项目后访问404错误

和我的/usr/local/nginx/sites-enabled/example.com是这样的:

 服务器{

        听IP:80;
        SERVER_NAME example.com;
        改写^ / https://example.com/$1永久(*);

       }

服务器 {

        听IP:443默认SSL;

        SSL上;
        ssl_certificate /etc/ssl/certs/myssl.crt;
        ssl_certificate_key /etc/ssl/private/myssl.key;

        ssl_protocols的SSLv3的TLSv1;
        的ssl_ciphers ALL:ADH:RC4 + RSA:+高:+ MEDIUM:-LOW:-SSLv2:-exp;

        SERVER_NAME example.com;

        访问日志/home/example/example.com/log/access.log;
        error_log中/home/example/example.com/log/error.log;

        }
 

解决方案   

使用亚马逊的EC2弹性IP地址,服务器实际上并不知道它与大多数其他服务器的IP。

所以,你需要告诉你的Linux允许进程绑定到非本地地址。只需添加以下行的/etc/sysctl.conf 文件:

 #允许进程绑定到非本地地址
#(必要阿帕奇/ nginx的亚马逊EC2)
net.ipv4.ip_nonlocal_bind = 1
 

,然后重新加载sysctl.conf的:

$的sysctl -p /etc/sysctl.conf中

这将是罚款重启。

I am running Ubuntu Hardy 8.04 and nginx 0.7.65, and when I try starting my nginx server:

$ sudo /etc/init.d/nginx start

I get the following error:

Starting 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 www-data www-data;
worker_processes  4;

events {
    worker_connections  1024;
}

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

    access_log /usr/local/nginx/logs/access.log;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay         on;

    keepalive_timeout  3;

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

    include /usr/local/nginx/sites-enabled/*;

}

and my /usr/local/nginx/sites-enabled/example.com looks like:

server {

        listen   IP:80;
        server_name  example.com;
        rewrite ^/(.*) https://example.com/$1 permanent;

       }

server {

        listen   IP:443 default ssl;

        ssl         on;
        ssl_certificate     /etc/ssl/certs/myssl.crt;
        ssl_certificate_key /etc/ssl/private/myssl.key;

        ssl_protocols       SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;

        server_name example.com;

        access_log /home/example/example.com/log/access.log;
        error_log /home/example/example.com/log/error.log;

        }

解决方案

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.