当前位置: 首页 > news >正文

【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端口被占用已经解决,如下图所示:

在这里插入图片描述

http://www.xdnf.cn/news/1303147.html

相关文章:

  • YOLOv8目标检测网络结构理论
  • 笔试——Day39
  • DevEco Studio 6.0.0 元服务页面跳转失败
  • Spring事物
  • 智能座舱软件架构设计的宏观决策框架
  • 【自动驾驶】自动驾驶概述 ② ( 自动驾驶技术路径 | L0 ~ L5 级别自动驾驶 )
  • 数据结构:二叉树的表示方式(Representation of Binary Trees)
  • 【测试工具】JMeter基本使用及MySQL数据库压力测试
  • Baumer高防护相机如何通过YoloV8深度学习模型实现驾驶员疲劳的检测识别(C#代码UI界面版)
  • python的美食交流社区系统
  • @[TOC](计算机是如何⼯作的) JavaEE==网站开发
  • 前端性能优化工具Performance面板实战指南
  • 【swift开发】SwiftUI概述 SwiftUI 全面解析:苹果生态的声明式 UI 革命
  • 【C#补全计划】事件
  • 【2D】圆上数值积分(半径方向用高斯积分减少点数)
  • 综合案例:Python 函数知识整合 — 学生成绩管理系统
  • Python 类(Class)学习
  • 【新手入门】Android基础知识(一):系统架构
  • 【Golang】:流程控制语句
  • 【Vibe Coding 工程之 StockAnalyzerPro 记录】- EP1.先写 PRD
  • 【秋招笔试】2025.08.15饿了么秋招机考-第一题
  • P4069 [SDOI2016] 游戏 Solution
  • 微信小程序 拖拽签章
  • Git版本控制器
  • spring中异步任务注解@Async和@scheduled的使用
  • 2025年机械制造、机器人与计算机工程国际会议(MMRCE 2025)
  • Docker Compose 入门教程
  • MySQL、PolarDB、PolarDB-X、TableStore、MongoDB、TiDB、ClickHouse选型
  • docker入门
  • Java 调用 Python 脚本:实现 HelloWorld