docker nginx运行后无法访问如何解决(docker,nginx,web开发)

时间:2024-05-06 04:46:56 作者 : 石家庄SEO 分类 : web开发
  • TAG :

## 1

最近在学docker部署,一开始打算将nginx先docker化的。

对照,进行自定义配置

将官方的nginx.conf复制出来后,修改添加了一些自定义,主要是屏蔽了default.conf,以及include文件夹 sites-available

#include/etc/nginx/conf.d/.conf;include/etc/nginx/sites-available/;

官方原先配置

usernginx;worker_processes1;error_log/var/log/nginx/error.logwarn;pid/var/run/nginx.pid;events{worker_connections1024;}http{include/etc/nginx/mime.types;default_typeapplication/octet-stream;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent""$http_x_forwarded_for"';access_log/var/log/nginx/access.logmain;sendfileon;#tcp_nopushon;keepalive_timeout65;#gzipon;include/etc/nginx/conf.d/*.conf;}

新建docker-compose.yml 简单的 指定images,名字,端口,挂载本地文件替代默认

version:'3'services:nginx-proxy:image:nginxcontainer_name:nginxports:-8081:80volumes:-./nginx/nginx.conf:/etc/nginx/nginx.conf:ro

## 2

运行docker-compose up 后,一直卡在attaching to nginx,浏览器也是无法访问该端口地址

starting nginx ... done
attaching to nginx

不知道问题出在哪里,查找资料后发现可以使用tty参数进行调试。

修改docker-compose.yml,增加一个配置tty:true。

dockerexec-itnginx/bin/bash

发现自己把默认的default.conf删除后,没有添加其他的配置文件,之前的sites-available文件夹是空的。

## 3

自己把自己坑了,添加

-./nginx/sites-available:/etc/nginx/sites-available:ro

并在sites-available添加一个配置文件。

/etc/nginx/sites-available#lsdefault.conf

运行后,对端口地址访问终于正常了

docker nginx运行后无法访问如何解决

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:docker nginx运行后无法访问如何解决的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:怎么干净的卸载docker下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18