首页 > 编程知识 正文

docker搭建nginx集群,docker nginx挂载目录

时间:2023-05-05 04:36:20 阅读:233551 作者:4673

在Docker下载Nginx镜像docker pull nginxdocker images 创建挂载目录(在下面的/data/nginx/html目录下编写自己的html文件,不挂载html目录也可以)mkdir -p /data/nginx/{conf,html,logs} 编写nginx,conf配置文件,并放在文件夹中#user  nobody;worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;       keepalive_timeout  65;    server {        listen       80;        server_name  localhost;        location / {            root   /usr/share/nginx/html;    #指定容器中的路径            index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html { root /usr/share/nginx/html;  #指定容器中的路径        }    }} 启动容器(挂载nginx.conf文件,html目录,和logs目录) docker run --name mynginx -d -p 82:80  -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -v /data/nginx/html:/usr/share/nginx/html -d nginx:latest

tip:如果你html中没有index.html网页会出现错误404,自己随意编写index.html就可以

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。