# Convert a SOCKS proxy to HTTP protocol using Nginx and Redsocks

**URL:** <https://forum.proxyrack.com/t/convert-a-socks-proxy-to-http-protocol-using-nginx-and-redsocks/68>\
**Category:** Help & Troubleshooting\
**Created:** [October 7, 2025, 3:59am UTC](https://forum.proxyrack.com/t/convert-a-socks-proxy-to-http-protocol-using-nginx-and-redsocks/68 "2025-10-07T03:59:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.proxyrack.com/sam/32/22_2.png) [@Sam](https://forum.proxyrack.com/u/Sam)\
**Post date:** [October 7, 2025, 3:59am UTC](https://forum.proxyrack.com/t/convert-a-socks-proxy-to-http-protocol-using-nginx-and-redsocks/68/1 "2025-10-07T03:59:32Z")

</div>

Some proxy providers or applications only provide SOCKS4 or SOCKS5 support and if you need to use HTTP protocol this can be issue.

Here’s a tutorial I just made to show how you can use **nginx** and **redsocks** to translate SOCKS proxy protocol to HTTP.

For this I will be using a VPS with **Ubuntu 22.04** installed.

You can paste all of these directly into the terminal

Initial setup (set variables) - replace username and password with your own. You can also use a different SOCKS proxy or different proxy provider altogether (you don’t have to use Proxyrack)

```auto
export SOCKS_HOST='usa.rotating.proxyrack.net'
export SOCKS_PORT=9000
export SOCKS_USER='username'
export SOCKS_PASS='password' # set your real password

export NGINX_PROXY_PORT=3128
export REDSOCKS_PORT=12345
export NGX_USER=www-data
export NGX_UID=$(id -u "$NGX_USER")

```

**Step 1) Install required packages**

Install the apps needed

```auto
sudo apt-get update
sudo apt-get install -y nginx redsocks iproute2

```

**Step 2) Configure Nginx forward proxy (HTTP-only) and reload**

Create nginx configuration files

```auto
sudo tee /etc/nginx/sites-available/http_forward_proxy.conf >/dev/null <<'NGINXCONF'
server {
    listen 3128; # HTTP forward proxy port
    resolver 1.1.1.1 1.0.0.1 valid=300s ipv6=off;
    resolver_timeout 10s;

    # allow/deny as needed; default deny all for safety
    allow 127.0.0.1;
    deny all;

    # For plain HTTP proxying (no HTTPS CONNECT support in this tutorial)
    location / {
        proxy_pass $scheme://$http_host$request_uri;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
NGINXCONF

sudo ln -sf /etc/nginx/sites-available/http_forward_proxy.conf /etc/nginx/sites-enabled/http_forward_proxy.conf
sudo nginx -t && sudo systemctl reload nginx

```

**Step 3) Configure redsocks to chain to upstream SOCKS5**

Create redsocks configuration files, enable and reload

```auto
sudo tee /etc/redsocks.conf >/dev/null <<EOF
base {
  log_debug = off;
  log_info = on;
  log = "syslog:daemon";
  daemon = on;
  redirector = iptables;
}

redsocks {
  local_ip = 127.0.0.1;
  local_port = ${REDSOCKS_PORT};
  ip = ${SOCKS_HOST};
  port = ${SOCKS_PORT};
  type = socks5;
  login = "${SOCKS_USER}";
  password = "${SOCKS_PASS}";
}
EOF

sudo systemctl restart redsocks
sudo systemctl enable redsocks
sudo systemctl is-active redsocks

```

**Step 4) Redirect Nginx worker traffic to redsocks (iptables via systemd)**

```auto
sudo tee /etc/systemd/system/iptables-redsocks.service >/dev/null <<EOF
[Unit]
Description=Apply iptables redirect for nginx -> redsocks
After=network-online.target redsocks.service
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/bash -lc 'iptables -t nat -N REDSOCKS 2>/dev/null || true; iptables -t nat -F REDSOCKS; iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN; iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN; iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN; iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN; iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN; iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN; iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN; iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN; iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports ${REDSOCKS_PORT}; iptables -t nat -D OUTPUT -p tcp -m owner --uid-owner ${NGX_UID} -j REDSOCKS 2>/dev/null || true; iptables -t nat -I OUTPUT -p tcp -m owner --uid-owner ${NGX_UID} -j REDSOCKS'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl restart iptables-redsocks
sudo systemctl enable iptables-redsocks
sudo systemctl is-active iptables-redsocks

```

**Step 5) Test through the proxy**

```auto
# Plain HTTP via proxy
curl -sS -o /dev/null -w "%{http_code}\n" -x http://127.0.0.1:${NGINX_PROXY_PORT} http://example.com

# HTTPS CONNECT is not supported by this HTTP-only config

# Direct SOCKS5 check (bypasses nginx/redsocks)
curl -sS --max-time 20 \
  --socks5 ${SOCKS_USER}:${SOCKS_PASS}@${SOCKS_HOST}:${SOCKS_PORT} \
  -o /dev/null -w "%{http_code}\n" http://api.ipify.org

```

**Step 6) Runtime sanity checks**

```auto
# Redsocks listening
ss -lntp | grep 127.0.0.1:${REDSOCKS_PORT}

# iptables redirect chain
sudo iptables -t nat -S REDSOCKS

# Services status
systemctl is-active redsocks
systemctl is-active iptables-redsocks

# Logs
sudo tail -n 80 /var/log/nginx/error.log
sudo tail -n 20 /var/log/nginx/access.log
sudo grep -i redsocks /var/log/syslog | tail -n 80

```

**Optional) Allow another client IP to use the proxy**

```auto
YOUR_IP="1.2.3.4" # replace with the client IP to allow

sudo sed -i "/allow 127.0.0.1;/a \\ allow ${YOUR_IP};" /etc/nginx/sites-available/http_forward_proxy.conf \
  && sudo nginx -t && sudo systemctl reload nginx

```

[![](https://canada1.discourse-cdn.com/flex036/uploads/proxyrack1/original/1X/64057d7b2214bcf5630e9325c05b6fd929dfdd99.jpeg "Converting SOCKS Proxy to HTTP Protocol with NGINX and Red Socks 🌐") ](https://www.youtube.com/watch?v=heReNeP0OIM)

**### Architecture (for reference)**

```auto
- Nginx listens on TCP 3128 and supports HTTP proxying (HTTPS CONNECT is not enabled in this tutorial).

- All outbound TCP from the Nginx worker user (`${NGX_USER}`, uid `${NGX_UID}`) is redirected by iptables to `redsocks` on 127.0.0.1:${REDSOCKS_PORT}.

- `redsocks` connects to the upstream SOCKS5 proxy with credentials and relays traffic.

```

**### Key files and logs**

```auto
- Nginx site: /etc/nginx/sites-enabled/http_forward_proxy.conf

- Redsocks config: /etc/redsocks.conf

- iptables redirect unit: /etc/systemd/system/iptables-redsocks.service

- Logs:

- Nginx: /var/log/nginx/access.log, /var/log/nginx/error.log

- Redsocks (via syslog): /var/log/syslog

```

**### Maintenance**

```auto
- Update credentials in `/etc/redsocks.conf` as needed, then `systemctl restart redsocks`.

- After any unit file changes: `systemctl daemon-reload`.

- Restrict `allow` rules in Nginx based on your access needs.

```
