[Docker]compose一键部署nginx

Docker-compose部署nginx

创建配置文件

mkdir -p /usr/local/docker/nginx
cat > /usr/local/docker/nginx/docker-compose.yml<<'EOF'
version: '3.1'
services:
    nginx:
        # 镜像名称
        image: nginx
        # 容器名字 docker run --name
        container_name: nginx
        # 开机自动重启
        restart: always
        ports:
            - '8090:80'
            - '8091:8080'
        volumes:
            - ./conf/nginx.conf:/etc/nginx/nginx.conf
            - ./conf.d:/etc/nginx/conf.d
            - ./stream.d:/etc/nginx/stream.d
            - ./html:/usr/share/nginx/html
EOF
mkdir -p /usr/local/docker/nginx/conf
mkdir -p /usr/local/docker/nginx/conf.d
mkdir -p /usr/local/docker/nginx/stream.d
mkdir -p /usr/local/docker/nginx/html
touch /usr/local/docker/nginx/conf/nginx.conf
touch /usr/local/docker/nginx/conf.d/default.conf
cd /usr/local/docker/nginx
docker-compose up -d nginx 

Nginx.conf

cat >/usr/local/docker/nginx/conf/nginx.conf<<'EOF'
user  nginx;
worker_processes  auto;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
worker_rlimit_nofile 65535;

error_log  /var/log/nginx/error.log error;
pid        /var/run/nginx.pid;


events {
    # 多路复用 内核2.6以上版本,大大提高Nginx性能
    use epoll;
    worker_connections  65535;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    proxy_read_timeout 240s;

    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;
    access_log off;
    client_header_buffer_size 10M;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  60;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
stream {
    include /etc/nginx/stream.d/*.conf;
}
EOF

网站配置

cat >/usr/local/docker/nginx/conf.d/web.conf<<'EOF'
server{
    listen       80;
    server_name  10.1.30.108;
    location / {
        root /usr/share/nginx/html/html80;
        index index.html index.htm;
    }
}
server{
    listen       8080;
    server_name  10.1.30.108;
    location / {
        root /usr/share/nginx/html/html8080;
        index index.html index.htm;
    }
}

EOF
mkdir -p /usr/local/docker/nginx/html/html80
mkdir -p /usr/local/docker/nginx/html/html8080
echo 'Hello Html80' > /usr/local/docker/nginx/html/html80/index.html
echo 'Hello Html8080' > /usr/local/docker/nginx/html/html8080/index.html

END

posted @ 2020-05-03 15:04  LeoShi2020  阅读(769)  评论(0编辑  收藏  举报