【服务器】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

脚本下载地址

相关推荐
计算机安禾1 天前
【Linux从入门到精通】第17篇:日志系统——系统运行的黑匣子
linux·运维·服务器
拍客圈1 天前
内容页底部 采集的同时 隐瞒封面图
服务器·php
MAVER1CK1 天前
Install VNC in Docker container
运维·docker·容器
SECS/GEM1 天前
SECS/GEM如何实现越南现场自定义消息
java·服务器·数据库
薛定谔的悦1 天前
光伏逆变器多协议接入——Modbus RTU 在新能源设备集成中的实践
linux·运维·服务器·bms
bksczm1 天前
Linux之基础开发工具(Ubuntu)之编译器
linux·运维·服务器
阿正的梦工坊1 天前
Registry是什么意思?镜像仓库
docker
姚青&1 天前
Linux 文件处理命令
linux·运维·服务器
枷锁—sha1 天前
【CTFshow-pwn系列】03_栈溢出【pwn 072】详解:无字符串环境下的多级 Ret2Syscall 与 BSS 段注入
服务器·网络·汇编·笔记·安全·网络安全
zjeweler1 天前
阿里云服务器利用宝塔搭建个人博客网站
服务器·阿里云·云计算