当前位置: 首页 > news >正文 有口碑的唐山网站建设松江新城投资建设集团发展有限公司网站 news 2025/11/1 2:34:11 有口碑的唐山网站建设,松江新城投资建设集团发展有限公司网站,枣庄做网站建设的公司,广州 建网站最近用containerd在部署nginx的时候#xff0c;发生了一个比较诡异的问题#xff0c;当笔者通过nerdctl stop把原来的nginx容器关闭#xff0c;然后再通过nerdctl run启动一个新的nginx容器的时候#xff0c;把原来的宿主机端口映射到这个新容器上#xff0c;但新启动的容…最近用containerd在部署nginx的时候发生了一个比较诡异的问题当笔者通过nerdctl stop把原来的nginx容器关闭然后再通过nerdctl run启动一个新的nginx容器的时候把原来的宿主机端口映射到这个新容器上但新启动的容器却无法通过映射的端口收到任何请求而且新容器启动顺利没有任何报错。这个问题的原因十分隐蔽而且一开始让人无从下手。本文介绍了这个问题的解决办法为被该问题困扰的同学提供一个脱困的思路。 1. 环境 出现问题的服务器环境长这样 $ sudo uname -a Linux ubuntu-1 5.4.0-121-generic #137-Ubuntu SMP Wed Jun 15 13:33:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux $ sudo nerdctl version Client:Version: v0.20.0OS/Arch: linux/amd64Git commit: e77e05b5fd252274e3727e0439e9a2d45622ccb9Server:containerd:Version: 1.6.6GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1同时还更新了cni网络插件到v1.1.1版本。 使用最新的nginx镜像 $ sudo nerdctl exec nginx-4087e nginx -v nginx version: nginx/1.25.02. 问题重现 首先启动一个nginx容器: $ sudo nerdctl run -d -v /home/linmao/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/linmao/nginx/cert:/cert/ -p 8000:8000 -p 4443:4443 nginx 15b4bc769d04e6c28ac895c0403085656e866a35f72157edd6b81aec5464cbe6其中映射了2个端口8000端口用来提供http端点4443端口用来提供https端点。 nginx.conf长这样 events {worker_connections 64; }http {resolver 8.8.8.8;server {listen 8000;# 这是部署在nginx服务器上层的网络入口防火墙的ip地址4443端口映射到本机的4443端口。rewrite ^(.*) https://xxx.xxx.xxx.xxx:4443$1 permanent;}server {listen 4443 ssl;# 这是笔者自签的证书ssl_certificate /cert/self_cert.pem;ssl_certificate_key /cert/self_key.pem;location ~ /(.*)$ {# 这是代理的后端服务的域名proxy_pass https://www.xxxx.com/$1;proxy_redirect off;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}} }此时8000端口和4443端口是正常的。 $ curl localhost:8000 html headtitle301 Moved Permanently/title/head body centerh1301 Moved Permanently/h1/center hrcenternginx/1.25.0/center /body /html$ curl localhost:4443 html headtitle400 The plain HTTP request was sent to HTTPS port/title/head body centerh1400 Bad Request/h1/center centerThe plain HTTP request was sent to HTTPS port/center hrcenternginx/1.25.0/center /body /html关闭这个容器之后再用同样的命令run一个新的nginx新的nginx启动日志是正常的但是该新nginx无法收到任何网络流量。映射出来的端口并没有被监听。 $ sudo nerdctl stop 15b4bc769d04 15b4bc769d04$ sudo nerdctl run -d -v /home/linmao/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/linmao/nginx/cert:/cert/ -p 8000:8000 -p 4443:4443 nginx b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8$ sudo nerdctl logs -f b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up$ curl localhost:8000 curl: (7) Failed to connect to localhost port 8000: No route to host $ curl localhost:4443 curl: (7) Failed to connect to localhost port 4443: No route to host$ netstat -ano|grep :8000 $ $ netstat -ano|grep :4443 $ 3. 问题的原因 遇到这样的问题笔者是一点不慌才怪马上打开iptables看一下nat表一下发现了一些不正常的地方列表较长不相关的规则被笔者去掉了留下的都是相关的规则。nat表的POSTROUTING链多了2个名为CNI-xxxxxx的规则并且增加了2个名称对应为CNI-xxxxx的链。另外CNI-HOSTPORT-DNAT的链增加了2个名为CNI-DN-xxx的规则同时增加了2个对应名称为CNI-DN-xxxxx的规则链。 $ sudo iptables -nL -t nat --line-numbers ... Chain POSTROUTING (policy ACCEPT) num target prot opt source destination ... 9 CNI-d7ad1e347f6ac6bffdae5988 all -- 10.4.0.54 0.0.0.0/0 /* name: bridge id: default-15b4bc769d04e6c28ac895c0403085656e866a35f72157edd6b81aec5464cbe6 */ 10 CNI-a294464dbb367262e6fa35c6 all -- 10.4.0.55 0.0.0.0/0 /* name: bridge id: default-b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8 */ ... Chain CNI-HOSTPORT-DNAT (2 references) num target prot opt source destination 1 CNI-DN-d7ad1e347f6ac6bffdae5 tcp -- 0.0.0.0/0 0.0.0.0/0 /* dnat name: bridge id: default-15b4bc769d04e6c28ac895c0403085656e866a35f72157edd6b81aec5464cbe6 */ multiport dports 8000,4443 2 CNI-DN-a294464dbb367262e6fa3 tcp -- 0.0.0.0/0 0.0.0.0/0 /* dnat name: bridge id: default-b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8 */ multiport dports 8000,4443 ... Chain CNI-DN-a294464dbb367262e6fa3 (1 references) num target prot opt source destination 1 CNI-HOSTPORT-SETMARK tcp -- 10.4.0.0/24 0.0.0.0/0 tcp dpt:8000 2 CNI-HOSTPORT-SETMARK tcp -- 127.0.0.1 0.0.0.0/0 tcp dpt:8000 3 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8000 to:10.4.0.55:8000 4 CNI-HOSTPORT-SETMARK tcp -- 10.4.0.0/24 0.0.0.0/0 tcp dpt:4443 5 CNI-HOSTPORT-SETMARK tcp -- 127.0.0.1 0.0.0.0/0 tcp dpt:4443 6 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:4443 to:10.4.0.55:4443 ... Chain CNI-DN-d7ad1e347f6ac6bffdae5 (1 references) num target prot opt source destination 1 CNI-HOSTPORT-SETMARK tcp -- 10.4.0.0/24 0.0.0.0/0 tcp dpt:8000 2 CNI-HOSTPORT-SETMARK tcp -- 127.0.0.1 0.0.0.0/0 tcp dpt:8000 3 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8000 to:10.4.0.54:8000 4 CNI-HOSTPORT-SETMARK tcp -- 10.4.0.0/24 0.0.0.0/0 tcp dpt:4443 5 CNI-HOSTPORT-SETMARK tcp -- 127.0.0.1 0.0.0.0/0 tcp dpt:4443 6 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:4443 to:10.4.0.54:4443 ... Chain CNI-d7ad1e347f6ac6bffdae5988 (1 references) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 10.4.0.0/24 /* name: bridge id: default-15b4bc769d04e6c28ac895c0403085656e866a35f72157edd6b81aec5464cbe6 */ 2 MASQUERADE all -- 0.0.0.0/0 !224.0.0.0/4 /* name: bridge id: default-15b4bc769d04e6c28ac895c0403085656e866a35f72157edd6b81aec5464cbe6 */ ... Chain CNI-a294464dbb367262e6fa35c6 (1 references) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 10.4.0.0/24 /* name: bridge id: default-b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8 */ 2 MASQUERADE all -- 0.0.0.0/0 !224.0.0.0/4 /* name: bridge id: default-b8bf8e71ce1578d2b1f79c5d66cb75d2287a0f0d942d978761124f2dc003b3b8 */ ...再看一下mangle表mangle表正常空的 $ sudo iptables -nL -t mangle --line-numbers Chain PREROUTING (policy ACCEPT) num target prot opt source destinationChain INPUT (policy ACCEPT) num target prot opt source destinationChain FORWARD (policy ACCEPT) num target prot opt source destinationChain OUTPUT (policy ACCEPT) num target prot opt source destinationChain POSTROUTING (policy ACCEPT) num target prot opt source destinationChain KUBE-IPTABLES-HINT (0 references) num target prot opt source destinationChain KUBE-KUBELET-CANARY (0 references) num target prot opt source destination再看一下filter表也正常不过在笔者的另一台机器里发现了fliter表也被增加了几个规则。不过在笔者尝试重现问题的时候并未发现filter表有异常。建议同学们也查一下这个表。 $ sudo iptables -nL -t filter --line-numbers这些新增的规则和规则链不会因为容器的停止而删除。后来笔者发现这些规则的新增是因为nginx.conf配置文件中server块的rewrite命令后边写了ip地址。 server {listen 8000;# 就是这一句写了ip地址导致出现了上边那些规则如果把ip地址改成localhost就不会出现上边的问题。rewrite ^(.*) https://xxx.xxx.xxx.xxx:4443$1 permanent;}4. 问题的解决 知道了原因就很好办了直接使用iptables -F 或者 iptables -D删掉多出来的规则就行了。有同学知道为什么nginx.conf把rewrite写成一个ip地址就会在iptables增加一些不会自动删除的规则和规则链的原因的吗快来评论区告诉笔者吧。 文章转载自: http://www.morning.qmxsx.cn.gov.cn.qmxsx.cn http://www.morning.rxpp.cn.gov.cn.rxpp.cn http://www.morning.lpcpb.cn.gov.cn.lpcpb.cn http://www.morning.mrskk.cn.gov.cn.mrskk.cn http://www.morning.zffn.cn.gov.cn.zffn.cn http://www.morning.jksgy.cn.gov.cn.jksgy.cn http://www.morning.sbrpz.cn.gov.cn.sbrpz.cn http://www.morning.qrksj.cn.gov.cn.qrksj.cn http://www.morning.hrgxk.cn.gov.cn.hrgxk.cn http://www.morning.rgnp.cn.gov.cn.rgnp.cn http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn http://www.morning.djgrg.cn.gov.cn.djgrg.cn http://www.morning.ndynz.cn.gov.cn.ndynz.cn http://www.morning.rdkgw.cn.gov.cn.rdkgw.cn http://www.morning.glnfn.cn.gov.cn.glnfn.cn http://www.morning.wddmr.cn.gov.cn.wddmr.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn http://www.morning.thmlt.cn.gov.cn.thmlt.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn http://www.morning.wknbc.cn.gov.cn.wknbc.cn http://www.morning.tmtrl.cn.gov.cn.tmtrl.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn http://www.morning.tpnxj.cn.gov.cn.tpnxj.cn http://www.morning.cfcpb.cn.gov.cn.cfcpb.cn http://www.morning.ltpmy.cn.gov.cn.ltpmy.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.wrtsm.cn.gov.cn.wrtsm.cn http://www.morning.ailvturv.com.gov.cn.ailvturv.com http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.xjkr.cn.gov.cn.xjkr.cn http://www.morning.hhskr.cn.gov.cn.hhskr.cn http://www.morning.nxbsq.cn.gov.cn.nxbsq.cn http://www.morning.tqhpt.cn.gov.cn.tqhpt.cn http://www.morning.yrbhf.cn.gov.cn.yrbhf.cn http://www.morning.bryyb.cn.gov.cn.bryyb.cn http://www.morning.deanzhu.com.gov.cn.deanzhu.com http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.nqypf.cn.gov.cn.nqypf.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.hymmq.cn.gov.cn.hymmq.cn http://www.morning.pdxqk.cn.gov.cn.pdxqk.cn http://www.morning.mtjwp.cn.gov.cn.mtjwp.cn http://www.morning.ghrhb.cn.gov.cn.ghrhb.cn http://www.morning.qkqzm.cn.gov.cn.qkqzm.cn http://www.morning.mfsjn.cn.gov.cn.mfsjn.cn http://www.morning.qzdxy.cn.gov.cn.qzdxy.cn http://www.morning.ypdmr.cn.gov.cn.ypdmr.cn http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.qbgdy.cn.gov.cn.qbgdy.cn http://www.morning.buyid.com.cn.gov.cn.buyid.com.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.hrzymy.com.gov.cn.hrzymy.com http://www.morning.rzczl.cn.gov.cn.rzczl.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.tllhz.cn.gov.cn.tllhz.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.cwqpl.cn.gov.cn.cwqpl.cn http://www.morning.mlwhd.cn.gov.cn.mlwhd.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.gqflj.cn.gov.cn.gqflj.cn http://www.morning.kgphc.cn.gov.cn.kgphc.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.pjxw.cn.gov.cn.pjxw.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn 查看全文 http://www.tj-hxxt.cn/news/266846.html 相关文章: 如何在局域网建立网站wordpress自定义应用 网站制作还花钱百度软件推广联盟 四川省城市建设培训中心 网站山西省建设厅招标网站 网站建设中 动态图片网站优化网站建站教程 成立网站有什么要求百度知道灰色词代发收录 制作简历模板网站o2o电子商务模式的特点 网站开发和桌面开发哪个难江门cms模板建站 苏州企业网站建设推广公司产品文案该怎么写 公司备案证查询网站荣耀官方网站 土木特网站建设安贞做网站公司 国外优秀app设计网站中国乐清新闻 如何在一个地方建设网站深圳建站公司外围 python网站开发 pdf定服装网站建设 自己切片视频做网站wordpress页面移动端 做医疗器械网站京东购物商城 12380网站建设情况汇报零基础学python要多久 浏览器正能量网站免费微信公众号小程序 网站搭建中114514甘肃网站建设专家 常熟智能网站建设大连招标网 苏州网站工作室佛山市住房建设局网站办事大厅 网站商城怎么做网络设计师证怎么考 商城网站建设系统网站前端设计外包公司 如何说服企业做网站余姚物流做网站 建设外贸网站案例dw网页制作在线编辑 内部网站建设依据文件wordpress卡车主题 免费网站加速服务购物网站首页制作代码 做自己的网站后台dw可以制作网站吗 室内设计素材网站大全想找可以在家做的手工活去什么网站 网页游戏大全免登录seo是广告投放吗 什么网站可以看女人唔易做生活服务网站开发与设计