2010-07-07 52 views
15

我運行Ubuntu 8.04哈迪和nginx的0.7.65,當我嘗試啓動我的nginx服務器:nginx的錯誤:(99:無法分配請求的地址)

$ sudo /etc/init.d/nginx start 

我得到以下錯誤:

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

其中「IP」是我的IP地址的佔位符。有人知道爲什麼會發生這種錯誤?這在EC2上運行。

我的nginx.conf文件看起來像這樣:

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/*; 

} 

和我/usr/local/nginx/sites-enabled/example.com樣子:

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; 

     } 

回答

0

可能有剩餘正在使用/在端口80偵聽的進程/程序。

您可以使用netstat -lp檢查。 殺死該進程並啓動nginx。

+0

嗯遺憾的是沒有什麼偵聽端口80。 – 2010-07-07 06:53:59

+0

嗯..任何快速CGI運行也許.. – 2010-07-07 10:53:19

+0

不...快速CGI ... – 2010-07-08 00:34:47

5

爲了避免硬編碼在配置IP地址,這樣做:

listen *:80 
0

與Amazon EC2的彈性IP地址,服務器實際上並不知道它與大多數其他服務器的IP。所以在Apache虛擬主機文件中至少你把*:80而不是你的彈性ip:80

然後它工作正常。所以理論上,對於nginx來說*:80應該是一樣的,但是當你得到[emerg]:bind()到0.0.0.0:80失敗(98:地址已經在使用中)。尚未找到解決方案。 。

39

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

所以你需要告訴你的linux允許進程綁定到非本地地址。只需添加以下行/etc/sysctl.conf文件:

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

,然後重裝你的sysctl.conf的:

$ sysctl -p /etc/sysctl.conf

,這將是在重新啓動的罰款。

1

正如kirpit上面提到你要允許Linux進程綁定到一個本地IP地址:

nano /etc/sysctl.conf 

# allow processes to bind to the non-local address 
net.ipv4.ip_nonlocal_bind = 1 

sysctl -p /etc/sysctl.conf 

然後,你要添加與您的彈性IP相關的私有IP地址和添加到您的網站配置:

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

刷新nginx的:

service nginx reload 

全部完成!

0

對於Amazon EC2和彈性IP,sysctl.conf將不起作用,因爲nginx仍然沒有在eth0上收聽。

所以,你需要listen *;

0

對於誰可能有這個在未來打交道的人,我只是看着我的私有IP在AWS實例,並綁定到這一點。我證實了nginx能夠公開聆聽並在此之後執行我的重寫。我無法執行*:PORT,因爲我有一臺內部服務器正在代理。

0

如果使用的是網絡管理器,你必須等待啓動服務之前提高網絡接口:

systemctl啓用NetworkManager - 等待 - online.service

相關問題