Docker-compose部署nginx
Docker-compose部署nginx
目录结构
.
| -- conf.d
| | -- nginx.conf
| -- dist
| | -- index.html
| | -- 50x.html
| -- compose-nginx.yaml
| -- startup.sh
compose-nginx.yaml
version: '3'
# docker network create nginx_bridge
networks:
nginx_bridge:
driver: bridge
services:
nginx:
image: nginx:stable-alpine
#image: nginx:1.19.1-alpine
container_name: nginx-alpine
restart: always
privileged: true
environment:
- TZ=Asia/Shanghai
ports:
- 8080:80
- 80:80
- 443:443
volumes:
- /etc/localtime:/etc/localtime:ro
#- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
- ./conf.d:/etc/nginx/conf.d
- ./log:/var/log/nginx
- ./dist:/opt/dist:ro
networks:
- nginx_bridge
nginx.conf
这里只需要包含server配置,这个配置会内包含在容器内的nginx.conf(主配置中)
server {
listen 80;
server_name 192.168.31.202;
client_max_body_size 1000M;
#root /opt/dist;
#client_max_body_size 20M;
# Load configuration files for the default server block.
location / {
root /opt/dist;
index index.html;
}
}
startup.sh
#! /usr/bin/bash
# 定义一个名称变量
network_name="nginx_bridge"
filterName=`docker network ls | grep $network_name | awk '{ print $2 }'`
if [ "$filterName" == "" ]; then
# 不存在就创建
docker network create $network_name
echo "Created network $network_name success!!"
fi
docker-compose -f ./compose-nginx.yaml up -d
docker ps -a
docker logs -f nginx-alpine
安装额外的gzip模块
虽然nginx有自带
FROM alpine:latest as builder
RUN apk add --no-cache --virtual .build-deps \
gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers binutils \
libxslt-dev gd-dev geoip-dev perl-dev libedit-dev \
bash alpine-sdk findutils \
gnupg libtool autoconf automake \
build-base wget ca-certificates \
git curl && \
cd /tmp && \
wget http://nginx.org/download/nginx-1.20.1.tar.gz && \
tar -zxvf nginx-1.20.1.tar.gz && \
cd nginx-1.20.1 && \
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index

浙公网安备 33010602011771号