是否可以将NGinx配置为对外部资源的代理?

时间:2019-05-15 15:41:58

标签: nginx

我有一个无法访问Internet的客户端。我需要更新它。该客户端已连接到我的有权访问@的计算机。 由于我已经在DOCKER容器中运行了NGINX,因此我尝试将其配置为将来自客户端的请求转发到@。

在客户端上,我尝试curl --proxy http://10.222.8.111:80 http://pkg.adfinis-sygroup.ch/centos/7.6.1810/os/x86_64/repodata/repomd.xml 从客户端看到的我的机器地址是10.222.8.111。

这是最后一个nginx配置,我尝试过:

if ($reseauTD) {
     rewrite ^(.*)$ /PROXY/$1;
}

location /PROXY/ {
        error_log /tmp/squid-error.log debug;
        access_log /tmp/squid-access.log;
        rewrite ^/PROXY/(.*)$  $1 break;
        resolver 8.8.8.8  ipv6=off ;
        proxy_pass  http://$http_host$uri$is_args$args:80;
        proxy_set_header Host $proxy_host;
        proxy_set_header X-Real-IP A.B.C.D;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect off;
}

A.B.C.D是我的机器的外部地址。 resseauTD在nginx.conf中定义为:

   geo $reseauTD {
        default         0;
        10.225.200.0/24 1;
        10.239.102.0/24 1;
        10.229.85.0/24  1;
        10.233.1.0/24   1;
        10.229.88.0/24  1;
    }

每次我在客户端上尝试curl命令时,都会在/tmp/squid-error.log文件中看到:

==> /tmp/squid-error.log <==
2019/05/15 17:21:53 [debug] 734#0: *2550086 http cl:-1 max:10485760
2019/05/15 17:21:53 [debug] 734#0: *2550086 rewrite phase: 3
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script regex: "^/PROXY/(.*)$"
2019/05/15 17:21:53 [notice] 734#0: *2550086 "^/PROXY/(.*)$" matches "/PROXY//centos/7.6.1810/os/x86_64/repodata/repomd.xml", client: 10.229.88.23, server: _, request: "GET http://pkg.adfinis-sygroup.ch/centos/7.6.1810/os/x86_64/repodata/repomd.xml HTTP/1.1", host: "pkg.adfinis-sygroup.ch"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script capture: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script regex end
2019/05/15 17:21:53 [notice] 734#0: *2550086 rewritten data: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml", args: "", client: 10.229.88.23, server: _, request: "GET http://pkg.adfinis-sygroup.ch/centos/7.6.1810/os/x86_64/repodata/repomd.xml HTTP/1.1", host: "pkg.adfinis-sygroup.ch"
2019/05/15 17:21:53 [debug] 734#0: *2550086 post rewrite phase: 4
2019/05/15 17:21:53 [debug] 734#0: *2550086 generic phase: 5
2019/05/15 17:21:53 [debug] 734#0: *2550086 generic phase: 6
2019/05/15 17:21:53 [debug] 734#0: *2550086 generic phase: 7
2019/05/15 17:21:53 [debug] 734#0: *2550086 generic phase: 8
2019/05/15 17:21:53 [debug] 734#0: *2550086 access phase: 9
2019/05/15 17:21:53 [debug] 734#0: *2550086 access phase: 10
2019/05/15 17:21:53 [debug] 734#0: *2550086 post access phase: 11
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "http://"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script var: "pkg.adfinis-sygroup.ch"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script var: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script var: ""
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: ":80"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http init upstream, client timer: 0
2019/05/15 17:21:53 [debug] 734#0: *2550086 epoll add event: fd:21 op:3 ev:80002005
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "Host: "
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script var: "pkg.adfinis-sygroup.ch"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "
"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "X-Real-IP: A.B.C.D
"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "X-Forwarded-For: "
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script var: "10.229.88.23"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "
"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: "Connection: close
"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: ""
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: ""
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: ""
2019/05/15 17:21:53 [debug] 734#0: *2550086 http script copy: ""
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "User-Agent: curl/7.29.0"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Accept: */*"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Proxy-Connection: Keep-Alive"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header:
"GET /centos/7.6.1810/os/x86_64/repodata/repomd.xml:80 HTTP/1.0
Host: pkg.adfinis-sygroup.ch
X-Real-IP: A.B.C.D
X-Forwarded-For: 10.229.88.23
Connection: close
User-Agent: curl/7.29.0
Accept: */*
Proxy-Connection: Keep-Alive

"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http cleanup add: 0000000001227280
2019/05/15 17:21:53 [debug] 734#0: *2550086 http finalize request: -4, "/centos/7.6.1810/os/x86_64/repodata/repomd.xml?" a:1, c:2
2019/05/15 17:21:53 [debug] 734#0: *2550086 http request count:2 blk:0
2019/05/15 17:21:53 [debug] 734#0: *2550086 post event 0000000001396540
2019/05/15 17:21:53 [debug] 734#0: *2550086 delete posted event 0000000001396540
2019/05/15 17:21:53 [debug] 734#0: *2550086 http run request: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml?"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream check client, write event:1, "/centos/7.6.1810/os/x86_64/repodata/repomd.xml"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream recv(): -1 (11: Resource temporarily unavailable)
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream resolve: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml?"
2019/05/15 17:21:53 [debug] 734#0: *2550086 name was resolved to 95.128.34.165
2019/05/15 17:21:53 [debug] 734#0: *2550086 get rr peer, try: 1
2019/05/15 17:21:53 [debug] 734#0: *2550086 stream socket 23
2019/05/15 17:21:53 [debug] 734#0: *2550086 epoll add connection: fd:23 ev:80002005
2019/05/15 17:21:53 [debug] 734#0: *2550086 connect to 95.128.34.165:80, fd:23 #2550088
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream connect: -2
2019/05/15 17:21:53 [debug] 734#0: *2550086 posix_memalign: 00000000013322B0:128 @16
2019/05/15 17:21:53 [debug] 734#0: *2550086 event timer add: 23: 90000:1557933803846
2019/05/15 17:21:53 [debug] 734#0: *2550086 post event 0000000001396600
2019/05/15 17:21:53 [debug] 734#0: *2550086 delete posted event 0000000001396600
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream request: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml?"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream send request handler
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream send request
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream send request body
2019/05/15 17:21:53 [debug] 734#0: *2550086 chain writer buf fl:1 s:240
2019/05/15 17:21:53 [debug] 734#0: *2550086 chain writer in: 0000000001227428
2019/05/15 17:21:53 [debug] 734#0: *2550086 writev: 240 of 240
2019/05/15 17:21:53 [debug] 734#0: *2550086 chain writer out: 0000000000000000
2019/05/15 17:21:53 [debug] 734#0: *2550086 event timer del: 23: 1557933803846
2019/05/15 17:21:53 [debug] 734#0: *2550086 event timer add: 23: 90000:1557933803852
2019/05/15 17:21:53 [debug] 734#0: *2550086 post event 000000000137E5F0
2019/05/15 17:21:53 [debug] 734#0: *2550086 post event 0000000001396600
2019/05/15 17:21:53 [debug] 734#0: *2550086 delete posted event 000000000137E5F0
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream request: "/centos/7.6.1810/os/x86_64/repodata/repomd.xml?"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream process header
2019/05/15 17:21:53 [debug] 734#0: *2550086 malloc: 0000000001147F50:16384
2019/05/15 17:21:53 [debug] 734#0: *2550086 recv: fd:23 305 of 16384
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy status 404 "404 Not Found"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Server: nginx"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Date: Wed, 15 May 2019 15:20:59 GMT"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Content-Type: text/html"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Content-Length: 162"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header: "Connection: close"
2019/05/15 17:21:53 [debug] 734#0: *2550086 http proxy header done
2019/05/15 17:21:53 [debug] 734#0: *2550086 xslt filter header
2019/05/15 17:21:53 [debug] 734#0: *2550086 posix_memalign: 00000000011E1160:4096 @16
2019/05/15 17:21:53 [debug] 734#0: *2550086 HTTP/1.1 404 Not Found
Server: nginx/1.10.2
Date: Wed, 15 May 2019 15:21:53 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
...

2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream recv(): -1 (11: Resource temporarily unavailable)在我看来似乎很可疑;以及2019/05/15 17:21:53 [debug] 734#0: *2550086 http upstream connect: -2,但我仍然不明白为什么以及我做错了什么事...

0 个答案:

没有答案