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

脚本下载地址

相关推荐
胡俊杰53916 分钟前
9月18日
服务器·网络
爱吃龙利鱼36 分钟前
nginx实现https安全访问的详细配置过程
运维·nginx·安全·云原生·https
Adolf_19931 小时前
Flask 设置session 自定义登录验证
服务器·前端·flask
SofterICer1 小时前
Profile Package Interpreter3.0-3.2
linux·运维·服务器
shuxianshrng1 小时前
鹰眼降尘模型
大数据·服务器·人工智能·经验分享·机器人
箬敏伊儿2 小时前
打包好的jar包,如何部署在服务器?——详细教程
java·服务器·python·jar
RunningOnMyWay2 小时前
CentOS 7 安装yum使用报错:Cannot find a valid baseurl for repo: base/7/x86_6
linux·运维·服务器·centos
Just_Paranoid2 小时前
828华为云征文|部署在线文件管理器 Spacedrive
docker·华为云·文件管理·flexus云服务器·spacedrive
玖石书2 小时前
Docker 容器网络技术
运维·docker·容器
金刚钻信息3 小时前
文件外发怎么保证安全
服务器·加密软件·文件加密