docker-compose容器化构建nginx服务
nginx的yml文件
cat nginx.yml
version: '3.1'
services:
nginx:
image: nginx:1.16
restart: always
environment:
TZ: Asia/Shanghai
volumes:
- /data/nginx/html:/usr/share/nginx/html
- /data/nginx/conf.d:/etc/nginx/conf.d
- /data/nginx/nginx.conf:/etc/nginx/nginx.conf
- /data/nginx/cache:/var/cache/nginx
ports:
- "80:80"
准备挂载路径
mkdir /data/nginx/html
mkdir /data/nginx/conf.d
mkdir /data/nginx/cache
准备配置
/data/nginx/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;
}
/data/nginx/conf.d/vbaaswebapp.conf
根据自己环境定义业务需要的配置
/data/nginx/html
将前端代码放在该路径下
启动
docker-compose -f nginx.yml up -d