一、拉取nginx镜像
[root@iZ2ze5ot8cnsficuqqnoj5Z ~]# docker pull nginx
或者通过Dockerfile 构建一个镜像
docker build -t nginx .
二、服务器架构
启动容器
[root@iZ2ze5ot8cnsficuqqnoj5Z ~]# docker run -d -p 80:80 nginx
[root@iZ2ze5ot8cnsficuqqnoj5Z ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e4ec9513915 nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp nice_yalow
进入容器
[root@iZ2ze5ot8cnsficuqqnoj5Z ~]# docker exec -i -t 5e4ec9513915 /bin/bash
查看nginx容器的基本配置
root@5e4ec9513915:/etc/nginx/conf.d# cat default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#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;
#}
}
如果修改了配置文件,需要重启一下容器
nginx -s reload
三、部署项目
![水印](https://img-blog.csdnimg.cn/20210312190732627.jpg)
背景图片 bc.jpg
index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to HEHAI!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
padding: 0px;
margin: 0px;
}
.time{
width: 100%;
height: auto;
z-index: 99;
font-size: 60px;
text-align: center;
padding-top: 30%;
color: rgb(94,166,240);
font-weight: 800;
}
.container{
width: 100%;
height: 100%;
position: absolute;
background-image: url("bc.jpg");
background-size: 100% 100%;
}
</style>
</head>
<body>
<div class="container" >
<div class="time" id="time">
</div>
</div>
</body>
<script type="text/javascript">
var mynow = new Date();//默认的获取的是当前时间
//通过调用日期对象的方法来重新获取当前的日期时间
//mynow.setFullYear(2016);
var year = mynow.getFullYear();//获取年
var month = mynow.getMonth()+1;//获取月
var day = mynow.getDate();//获取日
var hour =mynow.getHours();//获取小时
var minute =mynow.getMinutes();//获取分钟
var second =mynow.getSeconds();//获取秒
var strdate = year+"年"+month+"月"+day+"日 "+hour+":"+minute+":"+second;
document.getElementById("time").innerHTML=strdate;
console.log(strdate)
</script>
</html>
将两个文件都拷贝到/usr/share/nginx/html文件夹下,在宿主机的两个文件的同一个文件夹下:
[root@iZ2ze5ot8cnsficuqqnoj5Z home]# docker cp index.html 5e4ec9513915:/usr/share/nginx/html
访问服务器的网址