diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..6f82f94 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,55 @@ +name: Build and Push Multi-Arch Docker Image + +on: + push: + branches: + - main + tags: + - '*beta*' # Tags containing "beta" + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/tor-nginx-proxy + tags: | + type=raw,value=latest + type=sha,prefix=,format=long + type=ref,event=tag,enable=${{ github.ref_type == 'tag' && contains(github.ref_name, 'beta') }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + diff --git a/.gitignore b/.gitignore index 842a3c7..6639aea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.temp -tor/ \ No newline at end of file +tor/ +.cursor +*.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 64dfb1d..bdffebf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,26 @@ -FROM nginx:1.20-alpine +FROM nginx:alpine # Metadata about the docker image LABEL name="tor-nginx-proxy" LABEL version="1.0.0-beta-1.0" -LABEL maintainer="Harshit Budhraja (https://github.com/harshit-budhraja)" +LABEL maintainer="Harshit Budhraja (https://github.com/hrhv)" # Update packages and install tor RUN apk --update --allow-untrusted --repository http://dl-4.alpinelinux.org/alpine/edge/community/ add \ tor && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* +# Set default NGINX_PROXY_HOST placeholder (will be replaced by script if not set) +# Using a placeholder that envsubst won't touch +ENV NGINX_PROXY_HOST="__NGINX_HOST_PLACEHOLDER__" + # Copy nginx and tor configurations COPY default.conf.template /etc/nginx/templates/default.conf.template COPY torrc /etc/tor/torrc +# Add script to fix nginx host header (runs after template processing) +COPY fix-nginx-host.sh /docker-entrypoint.d/35-fix-nginx-host.sh +RUN chmod +x /docker-entrypoint.d/35-fix-nginx-host.sh + # Add script to start tor COPY start-tor.sh /docker-entrypoint.d/40-start-tor.sh RUN chmod +x /docker-entrypoint.d/40-start-tor.sh \ No newline at end of file diff --git a/README.md b/README.md index ba1e36f..bea2a6a 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ # Tor-nginx-proxy -![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/harshit-budhraja/tor-nginx-proxy?include_prereleases) +![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/hrhv/tor-nginx-proxy?include_prereleases) ![license](https://img.shields.io/badge/license-GPLv3.0-brightgreen.svg?style=flat) -[![Docker Hub pulls](https://img.shields.io/docker/pulls/harshitbudhraja/tor-nginx-proxy.svg)](https://hub.docker.com/r/harshitbudhraja/tor-nginx-proxy/) -![Docker Image Size (tag)](https://img.shields.io/docker/image-size/harshitbudhraja/tor-nginx-proxy/latest) +[![GHCR](https://img.shields.io/badge/GHCR-ghcr.io-blue)](https://github.com/hrhv/tor-nginx-proxy/pkgs/container/tor-nginx-proxy) +![Docker Image Size](https://ghcr-badge.egpl.dev/hrhv/tor-nginx-proxy/size) -[![Docker Hub badge](http://dockeri.co/image/harshitbudhraja/tor-nginx-proxy)](https://hub.docker.com/r/harshitbudhraja/tor-nginx-proxy/) +> **Note:** Container images are now hosted on GitHub Container Registry (GHCR). The super easy and quick way to setup your web presence on the [Tor](https://www.torproject.org) network using [NGINX's](https://www.nginx.com) [proxy_pass](https://dev.to/danielkun/nginx-everything-about-proxypass-2ona) directive inside a [Docker](https://en.wikipedia.org/wiki/Docker_(software)) [container](https://en.wikipedia.org/wiki/Container_(virtualization)). @@ -21,7 +21,7 @@ The super easy and quick way to setup your web presence on the [Tor](https://www 1. Setup the proxy server at the **first time** ```sh -docker run --restart=unless-stopped --rm --name tor-nginx-proxy -e "NGINX_PORT=80" -e "NGINX_PROXY_URL=" -p 3000:80 -v "/absolute/path/to/volume/dir/on/host/tor:/var/lib/tor/" harshitbudhraja/tor-nginx-proxy:latest +docker run --restart=unless-stopped --rm --name tor-nginx-proxy -e "NGINX_PORT=80" -e "NGINX_PROXY_URL=" -p 3000:80 -v "/absolute/path/to/volume/dir/on/host/tor:/var/lib/tor/" ghcr.io/hrhv/tor-nginx-proxy:latest ``` - With parameter `--restart=unless-stopped` the container will always restart on daemon startup or when it fails unexpectedly, unless it's explicitly stopped. @@ -63,13 +63,13 @@ is serving from the file by reading it in any editor or terminal itself: `cat /a **Using curl:** ```bash -curl https://raw.githubusercontent.com/harshit-budhraja/tor-nginx-proxy/master/docker-compose.yml --output docker-compose.yml +curl https://raw.githubusercontent.com/hrhv/tor-nginx-proxy/master/docker-compose.yml --output docker-compose.yml ``` **Using wget:** ```bash -wget -O docker-compose.yml https://raw.githubusercontent.com/harshit-budhraja/tor-nginx-proxy/master/docker-compose.yml +wget -O docker-compose.yml https://raw.githubusercontent.com/hrhv/tor-nginx-proxy/master/docker-compose.yml ``` 3. Modify value for the environment variable `NGINX_PROXY_URL` to configure your proxy pass url. When a request arrives to the container which is running over the tor network through tor-nginx-proxy, it proxies those requests to your application which must be accessible over the url you provide. (Tip: don't forget to include the protocol `http://` or `https://` and the port that your application is serving from). diff --git a/default.conf.template b/default.conf.template index 36a4682..652fdbe 100644 --- a/default.conf.template +++ b/default.conf.template @@ -3,8 +3,9 @@ server { location / { proxy_pass ${NGINX_PROXY_URL}; - proxy_set_header Host $host:$server_port; + proxy_set_header Host ${NGINX_PROXY_HOST}; proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip; diff --git a/docker-compose.yml b/docker-compose.yml index 35c53db..ab8c93e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,11 @@ ---- -version: '3' - services: tor-nginx-proxy: container_name: tor-nginx-proxy - image: harshitbudhraja/tor-nginx-proxy:latest + image: ghcr.io/hrhv/tor-nginx-proxy:latest restart: unless-stopped environment: - NGINX_PORT=80 - - NGINX_PROXY_URL= + # - NGINX_PROXY_HOST= ports: - 3000:80 volumes: diff --git a/fix-nginx-host.sh b/fix-nginx-host.sh new file mode 100644 index 0000000..fd1c7d8 --- /dev/null +++ b/fix-nginx-host.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Fix NGINX_PROXY_HOST in the generated nginx config if it's still the placeholder +# This runs after template processing but before nginx starts +# If NGINX_PROXY_HOST was not explicitly set (or is the placeholder), use nginx variables +if [ -z "$NGINX_PROXY_HOST" ] || [ "$NGINX_PROXY_HOST" = "__NGINX_HOST_PLACEHOLDER__" ]; then + # Replace placeholder with nginx variables $host:$server_port + sed -i 's/proxy_set_header Host __NGINX_HOST_PLACEHOLDER__;/proxy_set_header Host $host:$server_port;/g' /etc/nginx/conf.d/default.conf +fi + diff --git a/start-tor.sh b/start-tor.sh index a119ac7..b1abb9b 100644 --- a/start-tor.sh +++ b/start-tor.sh @@ -1,2 +1,8 @@ #!/bin/sh + +# Print Tor Onion URL to the console in purple color +# The value is stored in the file /var/lib/tor/hidden_service/hostname +echo -e "\033[35mTor Onion URL: \033[0m$(cat /var/lib/tor/hidden_service/hostname)" + +# Start tor tor -f /etc/tor/torrc & \ No newline at end of file