nginx 错误:(99:无法分配请求的地址) [英] nginx error: (99: Cannot assign requested address)
问题描述
我正在运行 Ubuntu Hardy 8.04 和 nginx 0.7.65,当我尝试启动我的 nginx 服务器时:
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
我收到以下错误:
Starting nginx: [emerg]: bind() to IP failed (99: Cannot assign requested address)
其中IP"是我的 IP 地址的占位符.有人知道为什么会发生该错误吗?这是在 EC2 上运行的.
where "IP" is a placeholder for my IP address. Does anybody know why that error might be happening? This is running on EC2.
我的 nginx.conf 文件如下所示:
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/*;
}
我的/usr/local/nginx/sites-enabled/example.com 看起来像:
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;
}
推荐答案
使用 Amazon EC2 和弹性 IP,服务器实际上并不像大多数其他服务器那样知道其 IP.
With Amazon EC2 and elastic IPs, the server doesn't actually know its IP as with most any other server.
所以你需要告诉你的linux允许进程绑定到非本地地址.只需将以下行添加到 /etc/sysctl.conf
文件中:
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
然后通过以下方式重新加载您的 sysctl.conf:
and then reload your sysctl.conf by:
$ sysctl -p/etc/sysctl.conf
重新启动就可以了.
这篇关于nginx 错误:(99:无法分配请求的地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!