Last active
March 12, 2026 10:29
-
-
Save phongphuhanam/a387c18d6fe50db697b41adf5c4b442a to your computer and use it in GitHub Desktop.
Simple nginx docker to quick host static files via http; wget -q -O - https://gist.githubusercontent.com/phongphuhanam/a387c18d6fe50db697b41adf5c4b442a/raw/nginx_quick_host_here.sh | bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SOURCE_ADDR=$1 | |
| if [ $2 ] | |
| then | |
| TARGET_ADDR=$2 | |
| else | |
| TARGET_ADDR=0.0.0.0:80 | |
| fi | |
| if [ $3 ] | |
| then | |
| DOCKER_NAME=$3 | |
| else | |
| DOCKER_NAME=nginx_proxy_all | |
| fi | |
| TMP_BUILD_DIR=./.cache/nginxcfg/ | |
| mkdir -p $TMP_BUILD_DIR | |
| # pushd $TMP_BUILD_DIR | |
| # TODO how to pass $SOURCE_ADDR and $TARGET_ADDR parameters | |
| tee $TMP_BUILD_DIR/default.conf >/dev/null << EOF | |
| upstream backend { | |
| server $SOURCE_ADDR; | |
| } | |
| server { | |
| listen $TARGET_ADDR; | |
| location / { | |
| proxy_pass http://backend; | |
| proxy_set_header Host \$host; | |
| proxy_set_header X-Real-IP \$remote_addr; | |
| proxy_pass_request_body off; | |
| proxy_set_header Content-Length ""; | |
| } | |
| } | |
| EOF | |
| echo "START nginx forward_all from $TARGET_ADDR to $SOURCE_ADDR, name=$DOCKER_NAME." | |
| docker run --init -d --name $DOCKER_NAME --log-driver=journald --log-opt tag="$DOCKER_NAME" --restart unless-stopped -v $TMP_BUILD_DIR/default.conf:/etc/nginx/conf.d/default.conf --network=host nginx:stable-alpine | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ $1 ] | |
| then | |
| PORT=$1 | |
| else | |
| PORT=4500 | |
| fi | |
| if [ $2 ] | |
| then | |
| DOCKER_NAME=$2 | |
| else | |
| DOCKER_NAME=nginxquickhost | |
| fi | |
| TMP_BUILD_DIR=/tmp/nginx_quickhost | |
| mkdir -p $TMP_BUILD_DIR | |
| pushd $TMP_BUILD_DIR | |
| docker build -t nginxquickhost -f - . <<EOF | |
| FROM nginx:stable-alpine | |
| RUN apk add --no-cache tzdata | |
| ENV TZ=Asia/Seoul | |
| RUN printf 'server {\n\tlisten 80;\n\tserver_name localhost;\n\tcharset utf-8;\n\troot /usr/share/nginx/html;\n\n\tlocation / {\n\t\tautoindex on;\n\t\tautoindex_localtime on;\n\t\tautoindex_exact_size off;\n\t\tdisable_symlinks off;\n\t}\n}\n' > /etc/nginx/conf.d/default.conf | |
| VOLUME ["/usr/share/nginx/html"] | |
| EOF | |
| popd | |
| rm -r $TMP_BUILD_DIR | |
| echo "START nginx quickhost at PORT $PORT with NAME $DOCKER_NAME.\nTry to access in one of the addresses:\n" | |
| hostname -I | tr ' ' '\n' | while read f; do echo "http://$f:$PORT"; done | |
| docker run --init -d --name $DOCKER_NAME --log-driver=journald --log-opt tag="$DOCKER_NAME" --restart unless-stopped -v $PWD:/usr/share/nginx/html:ro -p $PORT:80 nginxquickhost | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SOURCE_ADDR=$1 | |
| if [ $2 ]; then | |
| TARGET_ADDR=$2 | |
| else | |
| TARGET_ADDR=0.0.0.0:80 | |
| fi | |
| if [ $3 ]; then | |
| DOCKER_NAME=$3 | |
| else | |
| DOCKER_NAME=gh | |
| fi | |
| # TMP_BUILD_DIR=$HOME/.cache/git_gh_tools/ | |
| # mkdir -p $TMP_BUILD_DIR | |
| # pushd $TMP_BUILD_DIR | |
| # TODO how to pass $SOURCE_ADDR and $TARGET_ADDR parameters | |
| docker build --tag gh:latest - <<'EOF' | |
| ARG BASE_IMAGE=alpine | |
| FROM $BASE_IMAGE | |
| # ARGUMENTS | |
| LABEL maintainer="phongphu <phongphu>" | |
| RUN apk add --no-cache zsh git github-cli curl bash vim less tzdata rclone ncdu | |
| ENV TZ=Asia/Seoul | |
| ARG USER_NAME=dev | |
| ENV USERNAME=$USER_NAME | |
| ARG USER_HOME=/home/$USER_NAME | |
| ENV HOME=$USER_HOME | |
| ARG USERID=1000 | |
| ARG GROUPID=1000 | |
| ENV ZSH_DISABLE_COMPFIX=true | |
| # Replace 1000 with your user/group id | |
| # # | |
| # RUN addgroup -g $GROUPID docker && adduser $USERNAME -u $USERID -G docker -h $USER_HOME -s /bin/zsh -D docker | |
| RUN addgroup --gid $GROUPID docker && \ | |
| adduser --disabled-password --gecos "" \ | |
| --uid $USERID -G docker \ | |
| --home "$USER_HOME" --shell /bin/zsh \ | |
| "$USERNAME" | |
| USER ${USERNAME} | |
| RUN curl --silent --show-error --fail -L https://github.com/ohmyzsh/ohmyzsh/archive/refs/heads/master.zip --output $USER_HOME/ohmyzsh.zip && unzip $USER_HOME/ohmyzsh.zip -d $USER_HOME/ && rm -f $USER_HOME/ohmyzsh.zip && mv $USER_HOME/ohmyzsh-master $USER_HOME/.oh-my-zsh && cp $USER_HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc | |
| # RUN chown $USERID:$GROUPID -R $HOME/.oh-my-zsh | |
| # RUN /bin/zsh -c "omz plugin enable gh" | |
| # WORKDIR /home/${USERNAME} | |
| # Enable this line if fixuid is used. | |
| # ENTRYPOINT ["fixuid"] | |
| EOF | |
| echo "START gh docker name=$DOCKER_NAME." | |
| #--user "$(id -u):$(id -g)" | |
| docker run --init -i -t -d --restart unless-stopped --name=$DOCKER_NAME -v $PWD:$PWD -w $PWD --user "$(id -u):$(id -g)" gh:latest bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment