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
55 changes: 55 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -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

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.temp
tor/
tor/
.cursor
*.env
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).

Expand All @@ -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=<YOUR_APP_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=<YOUR_APP_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.
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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=<YOUR_APP_URL>
# - NGINX_PROXY_HOST=<YOUR_APP_URL_WITHOUT_PROTOCOL>
ports:
- 3000:80
volumes:
Expand Down
10 changes: 10 additions & 0 deletions fix-nginx-host.sh
Original file line number Diff line number Diff line change
@@ -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

6 changes: 6 additions & 0 deletions start-tor.sh
Original file line number Diff line number Diff line change
@@ -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 &