## 1
最近在學docker部署,一開始打算將nginx先docker化的。
對照,進行自定義配置
將官方的nginx.conf復制出來后,修改添加了一些自定義,主要是屏蔽了default.conf,以及include文件夾 sites-available
#?include?/etc/nginx/conf.d/.conf; include?/etc/nginx/sites-available/;
官方原先配置
user?nginx; worker_processes?1; error_log?/var/log/nginx/error.log?warn; pid????/var/run/nginx.pid; events?{ ??worker_connections?1024; } http?{ ??include????/etc/nginx/mime.types; ??default_type?application/octet-stream; ??log_format?main?'$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.log?main; ??sendfile????on; ??#tcp_nopush???on; ??keepalive_timeout?65; ??#gzip?on; ??include?/etc/nginx/conf.d/*.conf; }
新建docker-compose.yml 簡單的 指定images,名字,端口,掛載本地文件替代默認
version:?'3' services: ?nginx-proxy: ??image:?nginx ??container_name:?nginx ??ports: ???-?8081:80 ??volumes: ???-?./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
## 2
運行docker-compose up 后,一直卡在attaching to nginx,瀏覽器也是無法訪問該端口地址
starting nginx … done
attaching to nginx
不知道問題出在哪里,查找資料后發(fā)現可以使用tty參數進行調試。
修改docker-compose.yml,增加一個配置tty:true。
docker?exec?-it?nginx?/bin/bash
發(fā)現自己把默認的default.conf刪除后,沒有添加其他的配置文件,之前的sites-available文件夾是空的。
## 3
自己把自己坑了,添加
-./nginx/sites-available:/etc/nginx/sites-available:ro
并在sites-available添加一個配置文件。
/etc/nginx/sites-available#?ls default.conf
運行后,對端口地址訪問終于正常了
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END