记一次 Ubuntu 服务器 Nginx 无法启动问题

问题描述

sudo apt update
sudo apt install nginx

上述步骤安装完 Nginx 后,直接启动 Nginx 发现报错,无法启动,显示好像是 80 端口问题,但是通过 sudo lsof -i:80 命令查看,并没有进程占用 80 端口

排查问题

先停止所有和 nginx 相关的进程
sudo killall nginx

通过 sudo 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

查看上面的问题,网上很多都说是 etc/nginx/conf.d 目录下的 default.conf 配置文件的问题,但是安装完之后,并没有这个配置文件,于是加了个配置文件,发现报错不一样了,显示已经存在了重复的配置

nginx -v
nginx version: nginx/1.10.3 (Ubuntu)

这是我安装的版本

真正的默认的配置文件在 /etc/nginx/sites-available/default

注释掉 listen [::]:80 default_server; 即可

其它问题

# 还有其它问题就是服务器的 80 端口已被其它进程占用,nginx 启动是要监听 80 端口的,一种是查看占用 80 端口的服务进程,然后停止,还有就是修改 nginx 监听的端口

1、停止占用 80 端口的服务

# 查看占用 80 端口的服务
$ netstat -nap | grep 80
# 或者
$ sudo lsof -i tcp:80
# 找到进程,结束
$ kill -9 进程好
# 启动nginx
$ sudo nginx -c /etc/nginx/nginx.conf

2、修改 nginx 监听端口

$ vim /etc/nginx/sites-available/default

 listen 自定义端口 default_server;
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
247
粉丝
17
喜欢
213
收藏
58
排名:732
访问:9674
私信
所有博文
社区赞助商