File: proxy

package info (click to toggle)
nginx 1.28.2-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 9,972 kB
  • sloc: ansic: 169,643; sh: 819; perl: 439; python: 240; makefile: 130; cpp: 19
file content (68 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh

set -e

rm /etc/nginx/sites-enabled/default
cat <<EOF > '/etc/nginx/sites-enabled/default'
# --- backend (echo server) ---
server {
    listen 127.0.0.1:81;
    location /echo {
        default_type text/plain;
        return 200 "host_header=\$http_host\n";
    }
}
# --- proxy server ---
server {
    listen 127.0.0.1:80;
    location /test {
        proxy_pass http://127.0.0.1:81/echo;
        proxy_set_header Host \$host\$is_request_port\$request_port;
    }
}
EOF

nginx -t
invoke-rc.d nginx restart

exp='host_header=127.0.0.1
host_header=127.0.0.1
host_header=localhost:9999
host_header=localhost:9999
host_header=localhost:5678
host_header=localhost:5678
host_header=localhost:5678
host_header=localhost:5678'

out=`
# GET /test HTTP/1.1
# Host: 127.0.0.1
curl --http1.1 --silent --fail http://127.0.0.1:80/test;
curl --http2 --silent --fail http://127.0.0.1:80/test;
# GET /test HTTP/1.1
# Host: localhost:9999
curl --http1.1 --silent --fail -H "Host: localhost:9999" http://localhost:80/test;
curl --http2 --silent --fail -H "Host: localhost:9999" http://localhost:80/test;
# GET http://localhost:5678/test HTTP/1.1
# Host: 127.0.0.1
curl --http1.1 --silent --fail --request-target "http://localhost:5678/test" http://127.0.0.1:80/test
curl --http2 --silent --fail --request-target "http://localhost:5678/test" http://127.0.0.1:80/test
# GET http://localhost:5678/test HTTP/1.1
# Host: localhost:9999
curl --http1.1 --silent --fail --request-target "http://localhost:5678/test" -H "Host: localhost:9999" http://localhost:80/test
curl --http2 --silent --fail --request-target "http://localhost:5678/test" -H "Host: localhost:9999" http://localhost:80/test
`

if [ x"${out}" != x"${exp}" ]; then
  echo "output:"
  echo "====================="
  echo "${out}"
  echo "====================="
  echo "expected output:"
  echo "====================="
  echo "${exp}"
  echo "====================="
  exit 1
fi

exit 0