栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

虚拟机centos中docker启动容器nginx后,网页打不开,无法访问80端口,或被拒

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

虚拟机centos中docker启动容器nginx后,网页打不开,无法访问80端口,或被拒

今天碰到了个很奇怪的事情,在docker里面运行nginx的时候,成功启动,监听centos的80端口

结果访问一直被拒,网页也打不开

记录一下我的解决方法以及各种尝试

我的docker启动参数

docker run -itd --name nginx -p 80:80 nginx bash

先检查一下端口情况

netstat -tnlp

发现80端口正常被docker-proxy使用

之后又检查防火墙有没有给我拦住

firewall-cmd --list-all #检查防火墙的配置

刚开始是没有80端口的,我手动开启后网页依旧打不开

firewall-cmd --zone=public --add-port=80/tcp --permanent。#开启80端口

之后又尝试关闭防火墙,使用

systemctl stop firewalld.service 关闭防火墙

此时telnet可以连接80,网页依旧访问不到

我意识到可能是正在运行的nginx容器需要进入内部启动nginx

[root@localhost ~]# docker exec -it nginx(此处是你的容器name) bash  #进入容器内部
root@c431554b3059:/# service nginx start  #开启nginx
2022/05/09 03:35:02 [notice] 21#21: using the "epoll" event method
2022/05/09 03:35:02 [notice] 21#21: nginx/1.21.6
2022/05/09 03:35:02 [notice] 21#21: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/05/09 03:35:02 [notice] 21#21: OS: Linux 3.10.0-1160.62.1.el7.x86_64
2022/05/09 03:35:02 [notice] 21#21: getrlimit(RLIMIT_NOFILE): 1048576:1048576
root@c431554b3059:/# 2022/05/09 03:35:02 [notice] 22#22: start worker processes
2022/05/09 03:35:02 [notice] 22#22: start worker process 23
root@c431554b3059:/# exit    #退出容器

此时我可以打开网页了

 另外,我是个刚入行的菜鸟,错误的地方希望指正

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/869361.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号