No description
Find a file
2026-02-16 12:53:52 -06:00
.gitignore Initial reddit-proxy service implementation 2026-02-16 12:47:29 -06:00
DEPLOYMENT.md Add deployment guide and complete production setup 2026-02-16 12:53:52 -06:00
main.py Switch to Flask + gunicorn for better Python 3.14 compatibility 2026-02-16 12:53:17 -06:00
README.md Switch to Flask + gunicorn for better Python 3.14 compatibility 2026-02-16 12:53:17 -06:00
reddit-proxy.service Switch to Flask + gunicorn for better Python 3.14 compatibility 2026-02-16 12:53:17 -06:00
requirements.txt Switch to Flask + gunicorn for better Python 3.14 compatibility 2026-02-16 12:53:17 -06:00

Reddit Proxy Service

A lightweight FastAPI proxy service that routes Reddit API requests through a local machine on Tailscale, bypassing datacenter IP blocking.

Why?

Reddit blocks requests from datacenter IPs. This proxy allows cloud VMs on your Tailscale network to fetch Reddit data by routing through your home datacenter VM (which has a residential IP).

Setup

1. Install dependencies

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

2. Deploy as systemd service

Copy the service file:

sudo cp reddit-proxy.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable reddit-proxy
sudo systemctl start reddit-proxy

Check status:

sudo systemctl status reddit-proxy

View logs (real-time):

sudo journalctl -u reddit-proxy -f

View logs (last 50 lines):

sudo journalctl -u reddit-proxy -n 50

3. Test it locally

Before deploying as a service, test it:

# Activate venv
source venv/bin/activate

# Run locally (development)
python3 main.py

# In another terminal:
curl "http://localhost:8765/health"

4. Production notes

  • The service uses gunicorn with 4 worker processes for production
  • Logs go to systemd journal (use journalctl to view)
  • Port is 8765 on all interfaces (0.0.0.0)
  • Timeout is 60 seconds per request
  • Service auto-restarts on failure

Usage

From cloud VM (on Tailscale)

Replace emma-vm with your VM's Tailscale hostname or IP.

Python

import requests

response = requests.get(
    "http://emma-vm:8765/reddit/desmoines/new.json",
    params={"limit": 100}
)
posts = response.json()

Bash

curl "http://emma-vm:8765/reddit/desmoines/new.json?limit=100"

Cron job

# Instead of:
# https://www.reddit.com/r/desmoines/new.json?limit=100

# Use:
# http://emma-vm:8765/reddit/desmoines/new.json?limit=100

API Endpoints

Fetch subreddit

GET /reddit/{subreddit}/{sort}.json?limit=100&t=day

Parameters:

  • subreddit (required): Subreddit name (e.g., desmoines)
  • sort (required): Sort method (new, hot, top, controversial, rising)
  • limit (optional): Number of posts (1-1000, default 100)
  • t (optional): Time filter for top/controversial (hour, day, week, month, year, all)

Example:

GET /reddit/desmoines/new.json?limit=50
GET /reddit/desmoines/top.json?limit=100&t=day

Health check

GET /health

Statistics

GET /stats

Returns request counts, uptime, success rate.

Adding subreddits

Edit the ALLOWED_SUBREDDITS list in main.py:

ALLOWED_SUBREDDITS = [
    "desmoines",
    "iowa",
    "your_subreddit_here",
]

Then restart the service:

sudo systemctl restart reddit-proxy

Configuration

  • Port: 8765 (edit in service file or main.py)
  • Workers: 2 (edit in service file)
  • Timeout: 30 seconds per request
  • Rate limiting: None (relies on Reddit's rate limits)

Monitoring

Check if running

sudo systemctl status reddit-proxy
systemctl is-active reddit-proxy

View recent logs

sudo journalctl -u reddit-proxy -n 50

Get stats

curl http://localhost:8765/stats

Troubleshooting

Connection refused:

  • Make sure service is running: sudo systemctl start reddit-proxy
  • Check if port 8765 is in use: sudo lsof -i :8765

403 Forbidden (subreddit not whitelisted):

  • Add the subreddit to ALLOWED_SUBREDDITS in main.py
  • Restart service: sudo systemctl restart reddit-proxy

Reddit API errors:

Slow responses:

  • Check network connectivity to Reddit
  • Monitor with: curl http://localhost:8765/stats
  • Increase workers in service file if needed

Development

Run locally (not as service):

python3 -m uvicorn main:app --reload --port 8765

Future improvements

  • Rate limiting per client IP
  • Caching frequently accessed posts
  • Metrics/Prometheus integration
  • Kubernetes deployment
  • Multi-IP rotating proxy support

License

Public repo, no sensitive data committed.