linux - squid 两层反向代理问题
PHPz
PHPz 2017-04-17 15:08:37
[Linux讨论组]

场景:
局域网192.168.2.0/24中有多台主机
我的宿主机ip:192.168.2.35 (mac os)已安装squid代理 监听3128端口
宿主机中装了一个virtualbox:(centos)与宿主机使用nat模式连接,分配的ip是:192.168.33.10,这台centos中含有web应用,也装有squid,监听3128端口
想实现的是:
同网段其他client,比如192.168.2.36当这个ip使用192.168.2.35:3128代理时 可以访问到
192.168.2.35上centos(192.168.33.10)中的web应用。
目前的想法是:
在192.168.2.35上启动squid,监听3128端口,将请求转发至centos中的squid,
即:client-->192.168.2.35:3128--->192.168.33.10:3128--->web服务(192.168.33.10:80)

始终访问不成功,能否在不改变当前模式的情况下,实现代理访问?
而且在192.168.2.35上我将代理设置成127.0.0.1:3128 访问centos中的web应用还是失败,
其实就是做了2层代理。

192.168.2.35的squid配置如下:

➜  ~ cat /usr/local/etc/squid.conf |grep -v '#'


acl SSL_ports port 443
acl CONNECT method CONNECT

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow localhost manager
http_access deny manager



http_access allow localnet
http_access allow localhost


http_port 3128 accel vhost vport

cache_peer 192.168.33.10 parent 3128 0 no-query originserver


coredump_dir /usr/local/var/cache/squid

refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320
➜  ~

192.168.33.10中squid配置如下:

$ sudo cat /etc/squid/squid.conf|grep -v '#'


acl SSL_ports port 443
acl CONNECT method CONNECT

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow localhost manager
http_access deny manager



http_access allow localnet
http_access allow localhost


http_port 3128


coredump_dir /var/spool/squid

refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320

192.168.2.35上的squid访问日志:

1467302922.445      1 127.0.0.1 TCP_MISS/400 3647 GET http://www.xxx.com/ - FIRSTUP_PARENT/192.168.33.10 text/html

192.168.33.10上的squid访问日志:

1467302988.156      0 192.168.33.1 NONE/400 3582 GET /Artwork/SN.png - HIER_NONE/- text/html
1467302988.341      0 192.168.33.1 NONE/400 3576 GET /favicon.ico - HIER_NONE/- text/html

可以看到两边都有日志

代理访问时就报错:

Invalid URL

Some aspect of the requested URL is incorrect.

Some possible problems are:

Missing or incorrect access protocol (should be http:// or similar)

Missing hostname

Illegal double-escape in the URL-Path

Illegal character in hostname; underscores are not allowed.

Your cache administrator is root.

ps:能否在不改变当前模式下,实现2层代理后访问到正确web,代理访问www.baidu.com成功
taobao.com 成功,也没有产生日志,估计是https原因。

能否在不改变当前模式下,实现2层代理后访问到centos中的启动的web服务(nginx+php,nginx,php配置肯定都没有问题)

PHPz
PHPz

学习是最好的投资!

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号