docker部署前端项目比传统的方式稍微简单?其实也不见得,还是得看负责运维的同事能力如何。闲话少叙,开始正题。
一、查询镜像
docker search nginx
二、下载镜像
docker pull nginx
三、创建挂载目录
mkdir -p ./nginx/{html,logs,conf}
四、运行镜像容器
运行容器之前先将前端项目dist目录下的文件上传到挂载出来的html目录,然后设置端口号和时区。
docker run --name nginx -m 400m -p 8088:80 \
-v /home/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/logs:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-v /home/nginx/conf:/etc/nginx/conf.d \
-e TZ=Asia/Shanghai \
--privileged=true -d nginx
五、配置文件
1、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; }
2、default.conf文件
server {
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;
}
location /api{
proxy_pass 地址xxxx/api;
# access_log "logs/test.log";
}
}
PS:nginx的知识点还是比较多的,有需要的童鞋还是得系统的进行学习,以打下坚实的基础。