Nginx 学习笔记(七)如何解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
出现:nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 错误,有以下两种情况
1、80端口被占用
2、ipv4端口和ipv6端口冲突的问题
今天服务器安装了NodeJs,服务器实在卡的不行,就重启了,结果重启后,Nginx没有自动重启。果断的手动重启,结果问题来了
在ubuntu16.04上面尝试启动nginx,使用命令:
sudo /etc/init.d/nginx start
启动不了啊!出错了哎!提示的错误信息:
www@TinywanAliYun:~$ sudo /usr/local/openresty/nginx/sbin/nginx
nginx: [warn] could not build optimal variables_hash, you should increase either variables_hash_max_size: or variables_hash_bucket_size: ; ignoring variables_hash_bucket_size
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] still could not bind()
第一种情况,查看80端口是不是被占用了
www@TinywanAliYun:~$ netstat -anp |grep
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 内网IP:50852 外网IP:80 ESTABLISHED -
unix [ ACC ] STREAM LISTENING - /var/run/nscd/socket
unix [ ] STREAM CONNECTED -
问题上面怎么没有显示进程号

尽然没有仔细的看看这句话,要root权限啊!赶紧切换

这次看来是真有了,怎么是apache2,我都不知道什么时候安装的这个:ab 测试吗?
立马卸掉

重启Openresty,看看情况

果断没报错呀,访问:https://www.tinywan.com/ 一切正常
第二种情况
遇到这种问题我先用中文搜索了一下答案,发现大家都在装逼地说要杀nginx重复的进程。我试了下发现是扯淡,于是看了谷歌搜到的第一个英文页面,老外说是nginx先监听了ipv4的80端口之后又监听了ipv6的80端口,于是就重复占用了。更加坑人的是你去看了端口占用它又把80端口释放了,是不是很囧。 解决方案是编辑nginx的配置文件
我的配置
# 配置HTTP请求重定向
server {
# 监听所有的ipv4的地址
listen default_server;
# 监听所有的ipv6的地址
listen [::]: default_server;
server_name _;
# Redirect all HTTP requests to HTTPS with a Moved Permanently response.
return https://$host$request_uri;
# 过滤爬虫
if ($http_user_agent ~* "python|curl|java|wget|httpclient|okhttp") {
return ;
}
}
修改这一段
listen [::]: default_server;
修改后
listen [::]: ipv6only=on default_server;
果断重启后,正常
分析一下问题:
刚开始我是Nginx默认开机启动的,但是我今天又搞了个Openresty开启自启动,是不是冲突掉了
直接把Nginx启动脚本删掉 rm /etc/init.d/nginx ,又重启,结果还是不行
那就安装个sysv-rc-conf 工具看看,该命令可以查看到当前系统开启机动服务的情况。

果不其然,任然在开启启动项中呀!!!
我们再来看看通启动相应的服务的脚本文件是否存在

看到了吗!也在这里啊!啊哈
http://www.hankcs.com/appos/linux/fix-nginx-bind-err.html
Nginx 学习笔记(七)如何解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)的更多相关文章
- 解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx先监听了ipv4的80端口之后又监听了ipv6的80端口,于是就重复占用了.更加坑人的是你去看了端口占用它又把80端口释放了,是不是很囧. 解决方案是编辑nginx的配置文件 修改这一段:
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 错误解决
今天在做LNMP的时候,启动nginx服务,无法开启,导致网页打不开.把服务从起一下发现提示错误如下: Starting nginx: nginx: [emerg] bind() to 0.0.0.0 ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 报错信息 nginx: [emerg] bind() t ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address
http://blog.csdn.net/ownfire/article/details/7966645 今天在做LNMP的时候,启动nginx服务,无法开启,导致网页打不开.把服务从起一下发现提示错 ...
- Linux教程之:Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) 使用命令关闭占用80端口的程序 sudo fuser - ...
- 修改nignx报错Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) 这个错误是修改了nginx的配置时出现,表名80端口被程 ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决方案
前提:已经配置好静态IP以防万一,先安装好iptables服务(不管你装没装,先执行,免得后面添乱)[root@localhost ~]# yum install iptables-services[ ...
- Nginx学习笔记(三) Nginx基本数据结构
Nginx基本数据结构 话说学习一种编程语言,例如C语言,我们首先学的也是数据结构,这是以后开发程序的关键.为了更好更方便的开发Nginx,Nginx自己实现了很多适合nginx的数据结构. Ngin ...
- 【转】Nginx 学习笔记(十一)nginx下安装配置naxsi waf防火墙(附完整编译、配置)
原文地址:http://f2ex.cn/nginx-installed-configuration-naxsi-waf/ Naxsi 是第三方 nginx 模块 ,它和 Modsecurity 都是开 ...
随机推荐
- svn up出现类似svn: Error converting entry in directory '.' to UTF-8问题解决
执行svn up命令报错如下 # svn up svn: Error converting entry svn: Valid UTF- data (hex:) followed by invalid ...
- Nginx均衡TCP协议服务器案例
Nginx在企业运维中通常用来均衡HTTP协议,例如我们熟知的80.8080.8081等服务.因为大部分的服务都是http请求访问协议,那有时候需要用到TCP协议,如果来实现均衡呢? 默认nginx不 ...
- 【NOIP2015提高组】信息传递
https://www.luogu.org/problem/show?pid=2661 傻逼图论题,把我写成傻逼了. DFS找环,每个结点第二次访问时更新答案. 但是图会有几个连通块,所以要分开讨论. ...
- 基于Java使用Snmp4j进行监控与采集(snmptrap、snmpwalk、snmpget)
之前有在弄监控服务器这块的工作,今天来整体总结下.因为有些服务器(路由器.交换机等都是基于snmp协议的)必须使用snmp协议去监控采集和接收信息,所以必须去了解snmp相关内容,以及如何在基于jav ...
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- linux下分析Java程序内存汇总
使用pmap查看进程内存 执行命令 使用pmap能够查看某一个进程(非java的也能够)的内存使用使用情况, 命令格式: pmap 进程id 演示样例说明 比如执行: pmap 12358 显示结果例 ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 46:illegal multibyte sequence
一. 最近使用python写入文件时,出现了如下的错误: 但是content的内容是unicode编码,不知道怎么和gbk扯上了关系,对content使用encode()和decode(),用gbk, ...
- Java面向对象的特征
面向对象的特征 封装.继承.多态.(有人问第四个特征,再加抽象) 封装 体现形式(2种) 函数---提高代码的复用性 属性的私有化---将属性设置为私有的,通过提供对外的访问方法来间接操作对应属性,可 ...
- 【转】Win10下 python3和python2同时安装并解决pip共存问题
1.下载python3和python2 进入python官网,链接https://www.python.org/ 选择Downloads--->Windows,点击进入就可以看到寻找想要的pyt ...
- 自学Zabbix3.6.4-触发器triggers dependencies依赖关系
有时,一个主机的可用性取决于另一个主机.如果路由器坏了,某个路由器后面的服务器就会变得不可访问.对于两个主机都配置了触发器,您可能会收到两个主机的通知,而只有路由器是有罪的一方.这是主机之间的一些依赖 ...