nginx-docker:修改配置文件

dev_2.1.0
xueqingkun 1 year ago
parent 3c247de78d
commit 6ef9270a2b

@ -1,17 +1,25 @@
# 设置基础镜像 # 设置基础镜像
# 在137服务器中使用的是 rasa_dev:1.0.0镜像
FROM nginx:1.25 FROM nginx:1.25
ENV APP_HOME=/data/vp # 覆盖原镜像的启动脚本
COPY ./docs/docker-entrypoint.sh /docker-entrypoint.sh
# 设置工作目录
WORKDIR $APP_HOME
# 复制java jar 到容器中 # 删除默认的配置文件
COPY ./docs/conf.d /etc/nginx/conf.d RUN rm /etc/nginx/conf.d/default.conf
# 复制rasa配置文件到 rasa目录下
# 复制配置文件信息
COPY ./docs/conf.d/nginx.conf /etc/nginx/nginx.conf
COPY ./docs/conf.d/http.conf /etc/nginx/conf.d
COPY ./docs/conf.d/https.conf /etc/nginx/conf.d
COPY ./docs/conf.d/servers.conf.template /data/vp/nginx/conf/servers.conf.template
# 复制ssl证书信息
COPY ./docs/ssl /data/vp/nginx/ssl COPY ./docs/ssl /data/vp/nginx/ssl
# 复制静态文件信息
COPY ./html /usr/share/nginx/html
# 暴漏服务端口 # 暴漏服务端口
EXPOSE 80 443 EXPOSE 80 443

@ -1,3 +1,17 @@
# 构建步骤 # 构建步骤
- 修改配置文件 docs/conf.d/default.conf中的服务器地址 - 把前端文件放html目录下
- 运行Dockerfile文件构建镜像 docker build -t my/nginx:1.25 . - 运行Dockerfile文件构建镜像 docker build -t vp/nginx:1.25 .
# 启动说明
- docker run -itd --name nginx-test3 -p8819:80 -p443:443 \
- e UPSTREAM_WEB_SERVERS=192.168.10.138:8899 \
-e UPSTREAM_MANAGE_SERVERS=192.168.10.138:8891 vp/nginx:1.25
- itd : -itd : 无交互模式启动
- -p8819:80 -p443:443 : 端口映射
- UPSTREAM_WEB_SERVERS : 后端服务器地址,只允许有单个
- UPSTREAM_MANAGE_SERVERS : 管理服务器地址,只允许有单个
- vp/nginx:1.25 构建的镜像名称
# 注意事项
- 前端文件放到html目录下
- 后端服务器地址和管理服务器地址需要和docker run命令中的参数保持一致

@ -1,13 +1,3 @@
# 前台服务后端地址,多个地址可用与负载均衡
upstream web_servers {
server 192.168.10.138:8899;
}
#后管服务后端地址
upstream manage_servers {
server 192.168.10.138:8891;
}
server { server {
listen 80; listen 80;
listen [::]:80; listen [::]:80;

@ -0,0 +1,33 @@
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 /data/vp/nginx/conf/*.conf;
include /etc/nginx/conf.d/*.conf;
}

@ -0,0 +1,10 @@
# 前台服务后端地址,多个地址可用与负载均衡
# 解析以逗号分隔的多个 upstream 值
upstream web_servers {
server $UPSTREAM_WEB_SERVERS;
}
upstream manage_servers {
server $UPSTREAM_MANAGE_SERVERS;
}

@ -0,0 +1,56 @@
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
# /etc/nginx/conf.d/servers.conf 文件不存在,且 UPSTREAM_SERVERS 为 true执行替换
if [ ! -f "/data/vp/nginx/conf/servers.conf" ]; then
# 执行你的命令
echo "begin replace servers.conf ...."
envsubst '$UPSTREAM_WEB_SERVERS' < /data/vp/nginx/conf/servers.conf.template> /data/vp/nginx/conf/servers.tmp
envsubst '$UPSTREAM_MANAGE_SERVERS' < /data/vp/nginx/conf/servers.tmp > /data/vp/nginx/conf/servers.conf
fi
entrypoint_log() {
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
echo "$@"
fi
}
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
case "$f" in
*.envsh)
if [ -x "$f" ]; then
entrypoint_log "$0: Sourcing $f";
. "$f"
else
# warn on shell scripts without exec bit
entrypoint_log "$0: Ignoring $f, not executable";
fi
;;
*.sh)
if [ -x "$f" ]; then
entrypoint_log "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
entrypoint_log "$0: Ignoring $f, not executable";
fi
;;
*) entrypoint_log "$0: Ignoring $f";;
esac
done
entrypoint_log "$0: Configuration complete; ready for start up"
else
entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
Loading…
Cancel
Save