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

脚本下载地址

相关推荐
开开心心_Every14 分钟前
黄金价格软件国内外价格实时监控超方便
运维·服务器·游戏·智能手机·pdf·lua·perl
LMT_Lanmantech17 分钟前
HyperWorks许可:almutil显示Unit满了,数据到底准不准?
运维·服务器·算法
system_error_x18 分钟前
服务器的替代方案:从物理机到云原生的全面对比
运维·服务器·云原生
wei_shuo41 分钟前
极空间部署1Panel实战:应用商店装AList、Docker管理与远程访问
运维·docker·容器
朗尊软件技术团队43 分钟前
电商系统Docker容器化部署实践:从Dockerfile镜像瘦身到K8s滚动上线
运维·docker·云原生·容器·kubernetes
wespaul2 小时前
VeapAI 自然语言操作实战|第 07 篇:执行层——编排引擎与全局语义命令
服务器·人工智能·milvus
SensorFlow2 小时前
SensorFlow Docker 部署:从埋点接入到第一张看板
docker
lambo mercy2 小时前
Day4:流式传输
运维·服务器·网络
I'm Jie2 小时前
Rhost v2.0.0 版本发布!!!不止 SSH 终端,内置 AI Agent 支持自然语言操作远程服务器
运维·服务器·rust·开源·ssh·tauri·finalshell
Spatial3Ddddd2 小时前
2026空间三维重建服务商横向对比
java·服务器·人工智能