|
1 | 1 | # socks-nginx-module |
2 | 2 |
|
3 | | -An `nginx_http_proxy_module` fork with SOCKS5 support |
| 3 | +An nginx module that adds SOCKS5 proxy support to `proxy_pass`. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Route upstream traffic through a SOCKS5 proxy |
| 8 | +- Username/password authentication (RFC 1929) |
| 9 | +- SSL to upstream through the SOCKS tunnel (`proxy_pass https://...`) |
| 10 | +- IPv4, IPv6, and domain name address types |
4 | 11 |
|
5 | 12 | ## Building |
6 | 13 |
|
7 | | -nginx >= **1.18.0** is supported. |
| 14 | +Requires nginx **1.26.x** and PCRE2. |
8 | 15 |
|
9 | 16 | ```bash |
10 | | -# apt-get install git build-essential zlib1g-dev libpcre3 libpcre3-dev unzip |
| 17 | +git clone https://github.com/dannote/socks-nginx-module |
| 18 | +wget http://nginx.org/download/nginx-1.26.3.tar.gz |
| 19 | +tar -xzf nginx-1.26.3.tar.gz |
| 20 | +cd nginx-1.26.3 |
11 | 21 |
|
12 | | -$ git clone https://github.com/dannote/socks-nginx-module |
13 | | -$ wget http://nginx.org/download/nginx-1.18.0.tar.gz |
| 22 | +./configure --add-dynamic-module=../socks-nginx-module |
| 23 | +make |
| 24 | +make install |
| 25 | +``` |
14 | 26 |
|
15 | | -$ tar -xzvf nginx-1.18.0.tar.gz |
| 27 | +## Directives |
16 | 28 |
|
17 | | -$ cd nginx-1.18.0 |
| 29 | +### `socks_pass` |
18 | 30 |
|
19 | | -# See http://nginx.org/en/docs/configure.html for more configuration options |
20 | | -$ ./configure --add-dynamic-module=../socks-nginx-module |
| 31 | +Specifies the SOCKS5 proxy to route upstream traffic through. Must follow a `proxy_pass` directive. |
21 | 32 |
|
22 | | -$ make |
23 | | -# make install |
| 33 | +```nginx |
| 34 | +socks_pass socks5://proxy:1080; |
24 | 35 | ``` |
25 | 36 |
|
26 | | -## Configuring |
| 37 | +Credentials can be provided inline: |
| 38 | + |
| 39 | +```nginx |
| 40 | +socks_pass socks5://user:password@proxy:1080; |
| 41 | +``` |
| 42 | + |
| 43 | +### `socks_username` / `socks_password` |
| 44 | + |
| 45 | +Set SOCKS5 authentication credentials separately from the URL. |
| 46 | + |
| 47 | +```nginx |
| 48 | +socks_pass socks5://proxy:1080; |
| 49 | +socks_username myuser; |
| 50 | +socks_password mypassword; |
| 51 | +``` |
| 52 | + |
| 53 | +## Configuration examples |
| 54 | + |
| 55 | +### HTTP through SOCKS |
| 56 | + |
| 57 | +```nginx |
| 58 | +location / { |
| 59 | + proxy_pass http://httpbin.org/get; |
| 60 | + socks_pass socks5://proxy:1080; |
| 61 | +} |
| 62 | +``` |
27 | 63 |
|
28 | | -Sample HTTP to SOCKS5 proxy configuration: |
| 64 | +### HTTPS through SOCKS |
29 | 65 |
|
| 66 | +```nginx |
| 67 | +location / { |
| 68 | + proxy_pass https://httpbin.org/get; |
| 69 | + proxy_ssl_server_name on; |
| 70 | + socks_pass socks5://proxy:1080; |
| 71 | +} |
30 | 72 | ``` |
| 73 | + |
| 74 | +### With authentication |
| 75 | + |
| 76 | +```nginx |
31 | 77 | location / { |
32 | | - proxy_pass http://httpbin.org/get; |
33 | | - socks_pass socks5://proxy:1080; |
| 78 | + proxy_pass http://httpbin.org/get; |
| 79 | + socks_pass socks5://user:password@proxy:1080; |
34 | 80 | } |
35 | 81 | ``` |
36 | 82 |
|
37 | | -## Debugging |
| 83 | +## Development |
| 84 | + |
| 85 | +### Running tests |
38 | 86 |
|
| 87 | +```bash |
| 88 | +make ci |
39 | 89 | ``` |
| 90 | + |
| 91 | +Individual targets: `build`, `build-clang`, `build-asan`, `test`, `test-asan`, `lint`, `cppcheck`, `format`. |
| 92 | + |
| 93 | +### Debugging |
| 94 | + |
| 95 | +```bash |
40 | 96 | cd debug |
41 | | -docker-compose run --service-ports nginx |
| 97 | +docker compose run --service-ports nginx |
42 | 98 |
|
43 | 99 | (gdb) set follow-fork-mode child |
44 | 100 | (gdb) run |
45 | | -``` |
| 101 | +``` |
0 commit comments