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 都是开 ...
随机推荐
- HiveSchemaTool-Parsing failed. Reason- Unrecognized option- -dbType mysql
版本: Hive2.1 在linux上部署Hive的时候,初始化元数据的时候,出现HiveSchemaTool:Parsing failed. Reason: Unrecognized option: ...
- JavaScript学习笔记(一)数组排序
数组(Array)在JavaScript中是非常常用的类型,关于数组的排序,与C#等语法中的排序,乍看相似,其实差别比较大. Array的排序方法有两个,分别是reverse()和sort(). re ...
- 【POJ2823】Sliding Window
http://poj.org/problem?id=2823 题意:你有一个长度n的序列,分别询问[1,k],[2,k+1],[3,k+2],...,[n-k+1,n]这n-k+1个区间的最大值和最小 ...
- 使用boost::multi_index高速构建排行榜
使用boost::multi_index高速构建排行榜 前几天在boost的maillist上看到boost::multi_index将要支持ranked_index(邮件内容见附件2),这实乃我等苦 ...
- java文本编辑器v2.0 图形用户界面
package 文本编辑器; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; impor ...
- TCP传输中序号与确认序号的交互
本实验通过SSH远程登录server,然后使用Wireshark抓包分析. 开头的三次握手已经省略.关于序号的交互过程.须要记住一点:TCP首部中的确认序号表示已成功收到字节,但还不包括确认序号所指的 ...
- springboot整合redis
springboot-整合redis springboot学习笔记-4 整合Druid数据源和使用@Cache简化redis配置 一.整合Druid数据源 Druid是一个关系型数据库连接池,是阿 ...
- 安装Redis后RedisDesktopManager无法连接
1.查看端口,发现端口不通 2.修改安装redis的目录的redis.conf文件,把bind改为虚拟机的本机ip 3.关闭虚拟机的防火墙 #1.查看防火墙状态[root@localhost src] ...
- mac与centos下redis的安装与配置
前言 最近在用redis,下面简单写一下mac和centos下redis的安装与配置方法. 安装 mac下面 安装命令:brew intall redis 运行命令:brew services sta ...
- Android开发——使用LitePal开源数据库
前言:之前使用Android内置的数据库,感觉一大堆SQL语句,一不小心就错了,很难受,学习了这个LItePal的开源数据库,瞬间觉得Android内置的数据库简直是垃圾般的存在 LitePal Gi ...