【nginx端口】修改nginx全局模块、子模块配置,重启后依然监听80端口
说明:
1)其他项目已经使用nginx的80端口,所以需要更改nginx默认端口80
2)尝试将子配置文件80端口修改、全局nginx.conf配置也修改,服务启动失败
3)经过排查和验证,终于找到问题所在,是全局配置文件中添加了server模块。
问题描述:启动nginx报错,提示80端口已经使用,经过排查验证,是因为全局nginx.conf添加server模块,虽然没有写listen 80;选项,但是默认是监听80端口,如下图所示:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
解决方法:
1、修改配置文件
1)修改全局配置文件ngixn.conf
[root@kylin10 conf]# cat nginx.conf
http {
...# 修复安全漏洞server {error_page 502 =502 /empty.gif;location = /empty.gif {empty_gif;}}
...
}
请变更成以下:
[root@kylin10 conf]# cat nginx.conf
http {
...# 设置80端口server {listen 8xxx;server_name localhost;return 403;# 对502错误返回空响应error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}error_page 502 =502 /empty.gif;location = /empty.gif {empty_gif;expires 1s;}}
...
}说明:如果没有子目录配置文件,不用执行以下步骤
2)修改子目录配置文件shop-web.conf
[root@kylin10 conf]# cat vhosts/shop-web.conf
...
server {listen 82;server_name localhost;rewrite ^(.*)$ https://$server_name$1 permanent;
}
...
请变更成以下:
[root@kylin10 conf]# cat vhosts/shop-web.conf
...
server {listen 8xxx;server_name localhost;rewrite ^(.*)$ https://$server_name$1 permanent;
}
...3、重启nginx服务
nginx -t
systemctl restart nginx
systemctl status nginx说明:查看到nginx服务running状态,并且监听到你更改后的端口,nginx端口被占用已经解决,如下图所示: