nginx實(shí)踐結(jié)果:
把前后端分類的后臺頁面部署并訪問
環(huán)境
win10下+虛擬主機(jī)+docker
番外篇:
可以使用
在線:https://labs.play-with-docker.com/
步驟
- 1)拉取鏡像(不加對于的版本的默認(rèn)是最新的版本)
[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)端口映射且啟動服務(wù)
[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)訪問對應(yīng)服務(wù)
-
5)把Vue打包好的頁面HTML文件拷貝到宿主主機(jī)上(可以直接上傳整個(gè)dist)
文件同步
- 6)查看Nginx容器內(nèi)部的目錄結(jié)構(gòu)
[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默認(rèn)配置目錄信息 /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)替換對應(yīng)的目錄 把dist 下的文件拷貝到容器對于的/usr/share/nginx/html下
直接的替換目錄也可以,修改具體的名稱之后,拷貝整個(gè)的目錄到/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)關(guān)閉容器再查看訪問情況
redis實(shí)踐結(jié)果
安裝部署redis后侄泽,實(shí)現(xiàn)對應(yīng)的外網(wǎng)連接
步驟
- 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]#
本地以及有一個(gè)redis 4.0.14
- 2) 啟動redis容器
[root@localhost data]# docker run -di --name myredis -p 6379:6379 191c4017dcdd
8bd4c69fec011f7ecfacd55e398116dc82b5ce8ba4f2b7bf0d21b8a1f63b8b01
[root@localhost data]#
-
3) 外部鏈接redis容器