从Nginx反向代理到鱿鱼 [英] Reverse proxy from nginx to squid

查看:108
本文介绍了从Nginx反向代理到鱿鱼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Similar to this, I am trying to host a squid proxy behind nginx:

example.com -主站点

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

到目前为止,当我尝试使用鱿鱼代理时,它会抱怨访问非法页面,例如,如果我尝试访问 http://www.google.com ,我出现无效网址错误,提示网址/http://www.google.com (请注意前面的/).谁能说出为什么会这样,还是对Nginx进行了修复,或者可能在squid配置中提出了建议?

So far, when I try to use the squid proxy, it will complain about accessing an illegal page, for example, if I try to access http://www.google.com, I get an Invalid URL error saying that the URL /http://www.google.com (note the preceding /). Could anyone suggest why this is happening, or a fix for nginx or perhaps in the squid config?

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;
    }
}

https://imgur.com/qtgrZI9

鱿鱼的日志显示:

1423083723.857      0 127.0.0.1 NONE/400 3530 GET /http://www.google.com/ - HIER_NONE/- text/html

对于同一请求,nginx:

And nginx for the same request:

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" "-"

推荐答案

在nginx中:

proxy_pass http://@squid;

在鱿鱼中:

http_port 3128 vhost

,这就是解决此 https://imgur.com/qtgrZI9 错误

这篇关于从Nginx反向代理到鱿鱼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆