1 安装Docker(略)
2 拉取nginx镜像
docker pull nginx
3 创建文件目录
bev:静态网站名称
html:存放网站代码
nginx:存放nginx配置文件nginx.conf
conf.d:存放配置文件default.conf
logs:挂载nginx的日志
4 运行镜像,复制文件到宿主机
docker run -d -p 80:80 nginx
查看容器id
docker ps
复制容器中的nginx.conf和default.conf到宿主机
docker cp 容器ID:/etc/nginx/nginx.conf /home/bev/nginx/ docker cp 容器ID:/etc/nginx/conf.d/default.conf /home/bev/nginx/conf.d/
nginx.conf和default.conf都是配置文件,修改其一即可,下面修改default.conf
server { listen 80; listen [::]:80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; # 网站的根目录 index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
如果网站是打包到容器里面的修改根目录,我是宿主机挂载到容器的只需要将网站根目录映射到 /usr/share/nginx/html目录即可
5 移除nginx容器
docker rm -f 容器ID
6 重新运行容器
docker run -d -v /home/bev/html:/usr/share/nginx/html -v /home/bev/nginx/conf.d:/etc/nginx/conf.d -v /home/bev/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/bev/nginx/logs:/var/log/nginx -p 80:80 --name=bev nginx:latest
标签:docker,静态,前端,nginx,html,conf,Docker,bev,80 From: https://www.cnblogs.com/whjblog/p/17338771.html