docker配置Nginx总结
1、首先拉取相关的镜像:
命令:docker pull nginx
2、创建目录和文件,为容器挂载做准备
创建如下目录和文件夹
在conf文件夹下,添加默认配置,也可自定义
命令:vim nginx.conf
nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # user nobody; worker_processes 1 ; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024 ; } http { include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0 ; keepalive_timeout 65 ; gzip on; # 包括当前目录下的conf.d文件夹的所有配置 include ./conf.d/*.conf; } |
在conf.d文件夹下,创建默认配置
命令:vim default.conf
default.conf
1 2 3 4 5 6 7 8 9 | server { listen 80 ; server_name localhost; location / { root html; index index.html; } } |
3、创建运行容器
命令:docker run --name mynginx -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest
配置了nginx.conf,html页面logs的挂载
检测:挂载成功
本文作者:durtime
本文链接:https://www.cnblogs.com/durtime/p/15865938.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2021-02-06 每日日报