-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
40 lines (32 loc) · 1.29 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
server {
listen 8080;
listen [::]:8080;
server_name ~^(?<dialtun_service>[A-Za-z]+)-(?<dialtun_host>[A-Za-z0-9\-]+)\.;
location / {
if ($dialtun_service = "") {
return 400;
}
if ($dialtun_host = "") {
return 400;
}
set_by_lua_block $backend {
local DIGITS = {
A=2,B=2,C=2, D=3,E=3,F=3,
G=4,H=4,I=4, J=5,K=5,L=5, M=6,N=6,O=6,
P=7,Q=7,R=7,S=7, T=8,U=8,V=8, W=9,X=9,Y=9,Z=9
}
local letters = string.gsub(string.upper(ngx.var.dialtun_service), "[^A-Z]", "")
local prefix = string.sub(letters, 1, 3)
local numbers = string.gsub(prefix, "[A-Z]", DIGITS)
return ngx.var.dialtun_host .. ':' .. ((os.getenv("DIALTUN_BASE_PORT") or "64000") + numbers);
}
# We need the final URI to be absolute, but if we do the rewrite
# in a single pass then NGINX will see the `http://` prefix and
# generate a (302) redirect. The fix is to build the absolute
# URI in two `redirect` statements so that the NGINX logic will
# not trigger.
rewrite ^(.*)$ "://$backend$1";
rewrite ^(.*)$ "http$1" break;
proxy_pass http://localhost:1055;
}
}