docker挂载nginx配置文件

  • 在Docker下载Nginx镜像
docker pull nginx
docker 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就可以

猜你喜欢

转载自blog.csdn.net/qq_32711309/article/details/87809934