Skip to content

Commit 8ac25ac

Browse files
committed
Update README
1 parent 65575ec commit 8ac25ac

3 files changed

Lines changed: 83 additions & 24 deletions

File tree

README.md

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,101 @@
11
# socks-nginx-module
22

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
411

512
## Building
613

7-
nginx >= **1.18.0** is supported.
14+
Requires nginx **1.26.x** and PCRE2.
815

916
```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
1121

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+
```
1426

15-
$ tar -xzvf nginx-1.18.0.tar.gz
27+
## Directives
1628

17-
$ cd nginx-1.18.0
29+
### `socks_pass`
1830

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.
2132

22-
$ make
23-
# make install
33+
```nginx
34+
socks_pass socks5://proxy:1080;
2435
```
2536

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+
```
2763

28-
Sample HTTP to SOCKS5 proxy configuration:
64+
### HTTPS through SOCKS
2965

66+
```nginx
67+
location / {
68+
proxy_pass https://httpbin.org/get;
69+
proxy_ssl_server_name on;
70+
socks_pass socks5://proxy:1080;
71+
}
3072
```
73+
74+
### With authentication
75+
76+
```nginx
3177
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;
3480
}
3581
```
3682

37-
## Debugging
83+
## Development
84+
85+
### Running tests
3886

87+
```bash
88+
make ci
3989
```
90+
91+
Individual targets: `build`, `build-clang`, `build-asan`, `test`, `test-asan`, `lint`, `cppcheck`, `format`.
92+
93+
### Debugging
94+
95+
```bash
4096
cd debug
41-
docker-compose run --service-ports nginx
97+
docker compose run --service-ports nginx
4298

4399
(gdb) set follow-fork-mode child
44100
(gdb) run
45-
```
101+
```

ngx_http_socks_module.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,17 +1523,16 @@ ngx_http_socks_read_connect_response(ngx_http_request_t *r,
15231523
static void
15241524
ngx_http_socks_handshake_done(ngx_http_request_t *r, ngx_http_upstream_t *u)
15251525
{
1526-
ngx_connection_t *c;
1527-
1528-
c = u->peer.connection;
1529-
1530-
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http socks handshake done");
1526+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->peer.connection->log, 0,
1527+
"http socks handshake done");
15311528

15321529
#if (NGX_HTTP_SSL)
15331530

1534-
if (u->ssl && c->ssl == NULL) {
1531+
if (u->ssl && u->peer.connection->ssl == NULL) {
1532+
ngx_connection_t *c;
15351533
ngx_http_proxy_ctx_t *pctx;
15361534

1535+
c = u->peer.connection;
15371536
pctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
15381537

15391538
/*

ngx_http_socks_upstream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,8 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
37193719
}
37203720

37213721

3722+
#if (NGX_HTTP_SSL)
3723+
37223724
static void
37233725
ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
37243726
ngx_http_upstream_t *u, ngx_connection_t *c)
@@ -4024,6 +4026,8 @@ ngx_http_upstream_ssl_certificate(ngx_http_request_t *r,
40244026
return NGX_OK;
40254027
}
40264028

4029+
#endif
4030+
40274031

40284032
static ngx_int_t
40294033
ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,

0 commit comments

Comments
 (0)