Public Repository

Last pushed: 8 months ago
Short Description
Nginx under alpine
Full Description

start script

##################################################################

#!/bin/bash

NAME="local-nginx"
FPM="local-php"
RUNUID=33
RUNUSER=docker-runner
PORTS="-p 80 -p 443:443"
VOLUMES="-v /data:/var/www"
CONFPATH="/data/nginx_conf"
LOGPATH="/data/log/nginx"

#ssl site
WEBDIR=/var/www/yogoclub
DOMAIN=m.yogoclub.com
EMAIL=tinray1024@gmail.com

docker_run()
{
NEW_PID=docker run \ -dit \ --restart=always \ --name $NAME \ $PORTS \ --link $FPM:$FPM \ -v $CONFPATH:/etc/nginx/conf.d \ -v $LOGPATH:/var/log/nginx \ $VOLUMES \ andrewlees/nginx

ORIGIN_USERNAME=`docker exec $NAME getent passwd "$RUNUID" | cut -d: -f1`
if [[ "$ORIGIN_USERNAME" == "" ]]; then
    docker exec $NAME adduser -D -H -u $RUNUID $RUNUSER
else
    RUNUSER=$ORIGIN_USERNAME
fi

docker exec $NAME sed -i -e "s/#user  nobody/user $RUNUSER/g" /etc/nginx/nginx.conf
docker exec $NAME sh -c "/root/gen-ssl.sh $WEBDIR $DOMAIN $EMAIL"

echo $NEW_PID

}

PS=docker ps -a | grep $NAME

if [[ "$PS" != "" ]]; then
if [[ "$1" == "-f" ]]; then
docker stop $NAME > /dev/null
docker rm $NAME > /dev/null
PID=docker_run
else
if [[ $PS != "Up " ]]; then
PID=docker start $NAME
else
PID=echo $PS | awk '{print $1 ""}'
fi
fi
else
PID=docker_run
fi

docker exec -d $PID nginx

exit 0

##################################################################
reload script

##################################################################

#!/bin/bash

NAME="local-nginx"
FPM="local-php"
RUNUID=33
RUNUSER=docker-runner
PORTS="-p 80:80 -p 443:443"
VOLUMES="-v /data:/var/www"
CONFPATH="/data/nginx_conf"
LOGPATH="/data/log/nginx"

#ssl site
WEBDIR=/var/www/yogoclub
DOMAIN=m.yogoclub.com
EMAIL=tinray1024@gmail.com

PS=docker ps -l | grep $NAME

if [[ "$PS" != "" ]]; then
if [[ $PS != "Up " ]]; then
docker start $NAME > /dev/null
fi
PID=echo $PS | awk '{print $1 ""}'
else
PID=docker run \ -dit \ --restart=always \ --name $NAME \ $PORTS \ --link $FPM:$FPM \ -v $CONFPATH:/etc/nginx/conf.d \ -v $LOGPATH:/var/log/nginx \ $VOLUMES \ andrewlees/nginx

ORIGIN_USERNAME=`docker exec $NAME getent passwd "$RUNUID" | cut -d: -f1`
if [[ "$ORIGIN_USERNAME" == "" ]]; then
    docker exec $NAME adduser -D -H -u $RUNUID $RUNUSER
else
    RUNUSER=$ORIGIN_USERNAME
fi

docker exec $NAME sed -i -e "s/#user  nobody/user $RUNUSER/g" /etc/nginx/nginx.conf
docker exec $NAME sh -c "/root/gen-ssl.sh $WEBDIR $DOMAIN $EMAIL"

fi

docker exec -d $PID nginx -s reload

exit 0

Docker Pull Command
Owner
andrewlees

Comments (0)