nginx实践结果:
把前后端分类的后台页面部署并访问
环境
win10下+虚拟主机+docker
番外篇:
可以使用
在线:https://labs.play-with-docker.com/
步骤
- 1)拉取镜像(不加对于的版本的默认是最新的版本)
[root@localhost /]# docker pull nginx:latest
- 2)查看本地的镜像信息是否已拉取成功
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 891fcd9c5b3a 2 weeks ago 647MB
nginx latest f35646e83998 3 weeks ago 133MB
redis 4.0.14 191c4017dcdd 6 months ago 89.3MB
hell02 latest bf756fb1ae65 10 months ago 13.3kB
centos centos7.1.1503 e1430271e2f9 20 months ago 212MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
- 3)端口映射且启动服务
[root@localhost /]# docker run -di -p 80:80 nginx
a90e1eb657cb544f1c0f1fdd0445b355a4c992c7b03aed73b0601d880b624894
或者指定容器别名
[root@localhost /]# docker run -di --name mynginx -p 80:80 nginx
88343f5b3a3c120b5e1f2fa2ff5998da50729cf4466c0106bc04cfe3fb12d7ed
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88343f5b3a3c nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp mynginx
[root@localhost /]#
-
4)访问对应服务
-
5)把Vue打包好的页面HTML文件拷贝到宿主主机上(可以直接上传整个dist)
文件同步
- 6)查看Nginx容器内部的目录结构
[root@localhost /]# docker exec -it mynginx /bin/bash
root@88343f5b3a3c:/# ls
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@88343f5b3a3c:/# dir
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@88343f5b3a3c:/#
镜像把Nginx安装到了etc的下面
root@88343f5b3a3c:/# cd etc/
root@88343f5b3a3c:/etc# ls
adduser.conf ca-certificates.conf dpkg group- hosts ld.so.cache login.defs nginx passwd rc2.d resolv.conf shadow- systemd
alternatives cron.daily environment gshadow init.d ld.so.conf logrotate.d nsswitch.conf passwd- rc3.d rmt shells terminfo
apt debconf.conf fonts gshadow- inputrc ld.so.conf.d machine-id opt profile rc4.d securetty skel timezone
bash.bashrc debian_version fstab gss issue ldap mke2fs.conf os-release profile.d rc5.d security ssl ucf.conf
bindresvport.blacklist default gai.conf host.conf issue.net libaudit.conf motd pam.conf rc0.d rc6.d selinux subgid update-motd.d
ca-certificates deluser.conf group hostname kernel localtime mtab pam.d rc1.d rcS.d shadow subuid xattr.conf
root@88343f5b3a3c:/etc# ^C
root@88343f5b3a3c:/etc# cd nginx
root@88343f5b3a3c:/etc/nginx# cat nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
root@88343f5b3a3c:/etc/nginx#
- 6)查看Nginx配置信息对于的--- include /etc/nginx/conf.d/*.conf;
root@88343f5b3a3c:/etc/nginx/conf.d# cd /etc/nginx/conf.d/
root@88343f5b3a3c:/etc/nginx/conf.d# dir
default.conf
root@88343f5b3a3c:/etc/nginx/conf.d#
查看default.conf
root@88343f5b3a3c:/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;
#}
}
root@88343f5b3a3c:/etc/nginx/conf.d#
- 7)查看Nginx默认配置目录信息 /usr/share/nginx/html;
[root@localhost ~]# docker exec -it mynginx /bin/bash
root@88343f5b3a3c:/# cd /usr/share/nginx/html/
root@88343f5b3a3c:/usr/share/nginx/html# ls
50x.html index.html
root@88343f5b3a3c:/usr/share/nginx/html#
- 8)替换对应的目录 把dist 下的文件拷贝到容器对于的/usr/share/nginx/html下
直接的替换目录也可以,修改具体的名称之后,拷贝整个的目录到/usr/share/nginx/html下
[root@localhost data]# mv dist html
[root@localhost data]# ls
backup bak ceshi html jiao QQpro www wwwroot wwwroot2
[root@localhost data]#
覆盖
root@localhost data]# docker cp html mynginx:/usr/share/nginx/
[root@localhost data]#
-
9)查看访问情况
- 10)关闭容器再查看访问情况
redis实践结果
安装部署redis后,实现对应的外网连接
步骤
- 1)拉取镜像
[root@localhost data]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 891fcd9c5b3a 2 weeks ago 647MB
nginx latest f35646e83998 3 weeks ago 133MB
redis 4.0.14 191c4017dcdd 6 months ago 89.3MB
hell02 latest bf756fb1ae65 10 months ago 13.3kB
centos centos7.1.1503 e1430271e2f9 20 months ago 212MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
[root@localhost data]#
本地以及有一个redis 4.0.14
- 2) 启动redis容器
[root@localhost data]# docker run -di --name myredis -p 6379:6379 191c4017dcdd
8bd4c69fec011f7ecfacd55e398116dc82b5ce8ba4f2b7bf0d21b8a1f63b8b01
[root@localhost data]#
-
3) 外部链接redis容器