1、在物理机上创建3个目录 (config log www)
在www目录下,创建一个index.html 和 abc.html
在config目录下,创建一个 xxx.conf文件,比如 server.conf
server{
listen 80;
root /www;
index index.html index.htm;
server_name localhost;
}
2、启动docker
docker run -p 80:80 -v `pwd`/www:/www -v `pwd`/config:/etc/nginx/conf.d -v `pwd`/log:/var/log/nginx nginx
3、原理 nginx首先加载/etc/ngnix.conf文件,这个文件中 include /etc/nginx/conf.d/*.conf,所以需要写一个xxx.conf文件,并把conf目录映射到 /etc/nginx/conf.d
4、测试
打开 http://物理机IP 出现index.html内容。
打开http://物理机IP/abc.html 出现abc.html内容。