Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
access.log
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM alpine:3.22.1

# Install bash and other required tools
RUN apk add --no-cache bash openssl && \
rm -rf /var/cache/apk/* /usr/share/doc /usr/share/man
SHELL ["/bin/bash", "-c"]

# Create app directory and copy files
WORKDIR /app
COPY bash-server.sh mime.types /app/
COPY example/html /app/html
RUN chmod +x /app/bash-server.sh

# Environment variables that can be overridden
ENV HTTP_PORT=8080 \
BIND_ADDRESS=0.0.0.0 \
MIME_TYPES_FILE=/app/mime.types \
TMPDIR=/tmp \
LOGFORMAT="[%t] - %a %m %U %s %b %T" \
LOGFILE=/proc/1/fd/1 \
LOGGING=1 \
SESSION_COOKIE=BASHSESSID \
BASIC_AUTH=0 \
DOCUMENT_ROOT=/app/html

# Expose the configured port
EXPOSE $HTTP_PORT

# Run the server with the serveHtml option by default
CMD ["bash", "/app/bash-server.sh", "serveHtml"]
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A purely bash web server, no socat, netcat, etc...
* bash 5.2 (The patch will be included in bash5.2 - Alpha release already contains the patch)
* if bash version is under 5.2, patched loadable accept builtin (http://git.savannah.gnu.org/cgit/bash.git/tree/examples/loadables/accept.c) is needed, you have to apply accept.patch to your loadable accept.c file which is existed in bash source code, and than build and install the loadable accept builtin into BASH_LOADABLE_PATH specified in `bash-server.sh`


# How to
The port can be set by the env var: HTTP_PORT

Expand Down Expand Up @@ -73,3 +74,41 @@ Functions:
websocketStop
Stop the websocket server inside the function
```

# Docker Usage

You can run this web server using Docker. A Dockerfile is provided that builds an Alpine Linux-based image.

## Build the Docker Image
```bash
# Build the image
docker build -t bash-web-server .

# Run with custom HTML directory: http://localhost:8080
docker run -p 8080:8080 -v ${PWD}/example/html:/app/html bash-web-server
```

## Environment Variables

The following environment variables can be configured:

- `HTTP_PORT`: Server port (default: 8080)
- `BIND_ADDRESS`: Address to bind to (default: 0.0.0.0)
- `MIME_TYPES_FILE`: Path to mime types file (default: /app/mime.types)
- `TMPDIR`: Temporary directory (default: /tmp)
- `LOGFORMAT`: Log format (default: "[%t] - %a %m %U %s %b %T")
- `LOGFILE`: Log file path (default: /proc/1/fd/1 for Docker stdout)
- `LOGGING`: Enable/disable logging (default: 1)
- `SESSION_COOKIE`: Session cookie name (default: BASHSESSID)
- `BASIC_AUTH`: Enable/disable basic auth (default: 0)
- `DOCUMENT_ROOT`: Root directory for serving files (default: /app/html)

Example with multiple environment variables:
```bash
docker run -d \
-p 80:80 \
-e HTTP_PORT=80 \
-e BIND_ADDRESS=0.0.0.0 \
-e BASIC_AUTH=1 \
bash-web-server
```