【服务器】shell脚本之Docker创建nginx

powershell 复制代码
#!/bin/bash

# 定义目标目录和配置文件路径  
BASE_DIR="/opt/docker/nginx"

ETC_DIR="$BASE_DIR/etc"
ETC_CONF_DIR="$ETC_DIR/conf.d"
SSL_DIR="$ETC_CONF_DIR/ssl"
LOG_DIR="$BASE_DIR/log"

HTML_DIR="$BASE_DIR/html"

CONFIG_FILE="$ETC_DIR/nginx.conf"

mkdir -p "$BASE_DIR" "$ETC_DIR" "$ETC_CONF_DIR" "$SSL_DIR" "$LOG_DIR" "$HTML_DIR"

# 创建nginx.conf文件并写入基本配置
cat > "$CONFIG_FILE" << 'EOF'

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
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;
}

EOF

docker run --name nginx -p 80:80 -p 443:443 \
-v /opt/docker/nginx/html:/usr/share/nginx/html \
-v /opt/docker/nginx/log:/var/log/nginx \
-v /opt/docker/nginx/etc/conf.d:/etc/nginx/conf.d \
--mount type=bind,source=/opt/docker/nginx/etc/nginx.conf,target=/etc/nginx/nginx.conf \
-d nginx

脚本下载地址

相关推荐
晨曦丿6 分钟前
双11服务器
linux·服务器·网络
wanhengidc24 分钟前
UDP服务器主要是指什么意思?
服务器·网络协议·udp
李迟35 分钟前
在Linux服务器上使用kvm创建虚拟机
java·linux·服务器
从后端到QT42 分钟前
SRS流媒体服务器(8)源码分析之rtc/rtmp互相转码详解
运维·服务器·实时音视频
CodeWithMe1 小时前
Nginx入门进阶:从零到高手的实战指南
运维·nginx
高山莫衣1 小时前
Docker Desktop导致存储空间不足时的解决方案
docker·容器·eureka
鹏大师运维1 小时前
在银河麒麟V10 SP1上手动安装与配置高版本Docker的完整指南
linux·运维·docker·容器·麒麟·统信uos·中科方德
lovely_nn1 小时前
docker 介绍
docker·k8s
QMCY_jason1 小时前
linux 内存占用排查 vm.nr_hugepages
linux·运维·服务器
Ahlson1 小时前
【fnNAS】docker的nginx配置html
nginx·docker·容器·fnnas