nginx 错误,无法打开

nginx 错误,无法打开

请在我的服务器上启动 nginx,然后关注我

root@s45-****:/home/arabico# nmap 45.****

PORT   STATE SERVICE
22/tcp open  ssh
5/tcp open  smtp
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
root@s45-****:/home/arabico# sudo service apache2 stop
 * Stopping web server apache2                                                      * 
root@s45-****:/home/arabico# nmap 45.****

Starting Nmap 6.40 ( http://nmap.org ) at 2015-06-05 19:33 MST

PORT   STATE SERVICE
22/tcp open  ssh
25/tcp open  smtp

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
root@s45-***:/home/arabico# sudo service nginx restart
 * Restarting nginx nginx          
          [fail] 


root@s45-***:/home/arabico# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
nginx: configuration file /etc/nginx/nginx.conf test failed

root@s45***:/home/arabico# sudo nginx
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)

请问如何启动它

答案1

nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)

从错误消息来看,您的服务器上似乎禁用了 ipv6。编辑 nginx 默认服务器配置并将其更改为仅侦听 ipv4 或启用 ipv6。

listen 80 default_server;
# comment to disable ipv6
# listen [::]:80 default_server;

答案2

我刚刚删除了这行

听[::]:80 default_server ipv6only=on;

/etc/nginx/sites-available/default 并且它可以工作:D

答案3

感谢您提到 ipv6。

在我的例子中,我在 nginx conf 中看到一行

proxy_pass http://localhost:3028/;

当我在内核配置中禁用 ipv6 时,问题就出现了。重新启用 ipv6 可以解决问题,但这不是我想要的。

解决方案是删除

::1     localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

/etc/hosts

因此本地主机将始终遵循默认的 ipv4 目标,即127.0.0.1

删除该::1行就足够了。由于 ipv6 已完全禁用,因此我将删除所有行。

更改localhostnginx 配置也127.0.0.1可能解决这个问题。

相关内容