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

脚本下载地址

相关推荐
海阔天空任鸟飞~3 小时前
Linux 权限 777
linux·运维·服务器
IT瑞先生5 小时前
docker-compose下快速部署实操——持续更新...
运维·docker·容器
Kina_C6 小时前
Linux iptables 防火墙原理与实操——从四表五链到 NAT 配置
linux·运维·服务器·iptables
灵机一物11 小时前
企业选型参考:2026 CXL 内存扩展方案六强测评与落地指南
服务器·网络·数据库·人工智能
Web极客码11 小时前
如何用三段式确定性剪枝,为 LLM Agent 砍掉 35% 的 Token 成本?
服务器·人工智能·算法·机器学习
yeflx11 小时前
速腾Airy雷达使用记录
java·服务器·网络
爱码少年12 小时前
Docker遍历镜像生成导出镜像命令六法
docker·shell
公众号:fuwuqiBMC12 小时前
(转自“服务器BMC”)服务器BMC芯片——多Die(芯片)封装
运维·服务器·人工智能
jsons112 小时前
autofs挂载
linux·服务器·网络
gs8014013 小时前
【实战】记一次 Linux 服务器入侵排查:grok-agent 后门木马深度剖析与彻底清理
linux·运维·服务器