从nginx到squid的反向代理

apt*_*moo 6 proxy reverse-proxy nginx squid http-proxy

类似,我试图在 nginx 后面托管一个鱿鱼代理:

example.com - 主要站点

relay.example.com - 鱿鱼服务器。

到目前为止,当我尝试使用 squid 代理时,它会抱怨访问非法页面,例如,如果我尝试访问http://www.google.com,我会收到一个 Invalid URL 错误,指出该 URL /http://www.google.com(注意前面的 /)。任何人都可以建议为什么会发生这种情况,或者修复 nginx 或者可能在鱿鱼配置中?

upstream @squid {
    server localhost:3128;
}

server {
    listen 80;
    server_name relay.example.com;

    location / {
        proxy_pass http://@squid/$scheme://$host$uri;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Request-URI $request_uri;

        proxy_redirect off;
    }
}
Run Code Online (Sandbox Code Playgroud)

https://imgur.com/qtgrZI9

鱿鱼的日志给出:

1423083723.857      0 127.0.0.1 NONE/400 3530 GET /http://www.google.com/ - HIER_NONE/- text/html
Run Code Online (Sandbox Code Playgroud)

和 nginx 用于相同的请求:

12.34.56.78 - - [04/Feb/2015:16:02:03 -0500] "GET http://www.google.com/ HTTP/1.1" 400 3183 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0" "-"
Run Code Online (Sandbox Code Playgroud)

小智 4

在 Nginx 中:

proxy_pass http://@squid;
Run Code Online (Sandbox Code Playgroud)

在鱿鱼中:

http_port 3128 vhost
Run Code Online (Sandbox Code Playgroud)

这就是修复此https://i.stack.imgur.com/9FSB8.jpg错误所需的全部内容

  • 实际上你还需要允许直接转发,如下所示:`http_port 3128 vhost allowed-direct` (squid 4.6-1+deb10u1) (2认同)
  • 另外,新的鱿鱼版本中已弃用“vhost”,我正在使用“accel”安装 (2认同)