蓝色动力网络

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3950|回复: 0

利用反向代理解决大陆80端口被封问题(squid和nginx)

[复制链接]
发表于 2012-4-6 09:00:50 | 显示全部楼层 |阅读模式
大陆的网络环境,都在天朝神兽的制度下让我等小P民悲剧一片;动不动就拔网线、封机房;现在更厉害的一招,从网关封杀你的80端口,一旦被封,网站域名就无法访问;
nginx:
以上便废话,下面转入正题,其它就不帖了,直接给代码,利用nginx的反向代理功能,一般大家都很看懂,也不多记录了;
server {
        listen  80;
        server_name     a.itxbo.com;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header REMOTE-HOST $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log      off;
        location / {
                        proxy_pass      http://192.168.1.100:81;
                }
        }


server {
        listen  80;
        server_name     b.itxbo.com;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header REMOTE-HOST $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log      off;
        location / {
                        proxy_pass      http://www.baidu.com:8080;
                }
        }
squid:
1、squid.conf配置
#squid.conf
#服务器IP 192.168.1.102
#监听服务器的80端口,透明代理,支持域名和IP的虚拟主机
http_port 192.168.1.102:80 vhost vport

#Squid信息设置
visible_hostname cdn.s.baidu.com
cache_mgr myname@139.com

#基本设置

cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65535 bytes
client_persistent_connections on
server_persistent_connections on
half_closed_clients off
persistent_request_timeout 30 second

#cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
cache_swap_log /usr/local/squid/var/logs/swap.log

logfile_rotate 3

acl AdminBoxes src 127.0.0.1 192.168.1.102
acl Purge method PURGE

http_access allow AdminBoxes Purge
http_access deny Purge

#设置Squid所能使用的内存共40MB,这个值因人而异,每次处理缓存大小为512MB,当缓存空间使用达到95%时新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动
cache_mem 1024 MB
cache_swap_low 95
cache_swap_high 98

#最大缓存文件大小,超过这个值则不缓存,这个值因人而异,maximum_object_size_in_memory #装入内存缓存的文件大小,这个值对Squid的性能影响比较大,因为默认值是8K,超过8K的文件都不装入内存,而实际应用中很多网页和图片等都超过 8KB, 个人认为如果缓存不装入内存而存在磁盘上,性能和apache直接读取磁盘文件没什么区别,甚至不如直接访问apache,现在设置成小于4兆的文件通通装入内存缓存.
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_replacement_policy lru
memory_replacement_policy lru

#max_filedesc 65535

#磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是2048MB,都是 16*256 级子目录  /www/squid/cache 可以自定义
#cache_dir ufs /
cache_dir ufs /usr/local/squid/var/cache 2048 16 256

#限制同一IP客户端的最大连接数
#acl OverConnLimit maxconn 16
#http_access deny OverConnLimit

#防止天涯盗链,转嫁给百度
acl tianya referer_regex -i tianya
http_access deny tianya
deny_info tianya

#防止被人利用为HTTP代理,设置允许访问的IP地址
acl myip dst 192.168.1.102
acl myip dst 192.168.1.103
acl myip dst 192.168.1.104
http_access deny !myip

#防止百度机器人爬死服务器
acl AntiBaidu req_header User-Agent Baiduspider
http_access deny AntiBaidu

#允许本地管理
acl Manager proto cache_object
acl Localhost src 127.0.0.1 192.168.1.102
http_access allow Manager Localhost
http_access deny Manager

#仅仅允许80端口的代理

acl all src 0.0.0.0/0.0.0.0
acl Safe_ports port 80 # http
http_access deny !Safe_ports
http_access allow all

#设置不想缓存的目录或者文件类型
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY

#2.6的反向代理加速配置
#代理到本机的80端口的服务,仅仅做为原始内容服务器
cache_peer 192.168.1.102 parent 81 0 no-query originserver name=sc102
cache_peer 192.168.1.103 parent 80 0 no-query originserver name=sc103
cache_peer 192.168.1.104 parent 81 0 no-query originserver name=sc104

cache_peer_domain sc102 parent 102.x.com
cache_peer_domain sc103 parent 103.x.com
cache_peer_domain sc104 parent 104.x.com

#错误文档
#error_directory /usr/share/squid/errors/Simplify_Chinese
2、/etc/hosts配置
192.168.1.102   102.x.com
192.168.1.103   103.x.com
192.168.1.104   104.x.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

蓝色动力网络微信平台
网站管理,业务合作联系邮箱: admin#lansedongli.com    QQ:13412492 限网站业务问题.
网站帐号、密码、密保找回请使用注册邮箱,发送邮件至 password#lansedongli.com ,否则不予受理.
免责声明:本论坛所有文字和图片仅代表其个人观点.
本站某些资料或文章来自于互联网,不代表本站观点,如果侵犯了您的权益,请来信告知,我们会在三天内删除.
为了给大家一个更好的交流场所,请勿在本论坛发表与中华人民共和国法律相抵触的言论,请合作,谢谢!
Copyright © 2007-2019 Corporation Powered by网吧系统 版权所有    转载请注明!
浙ICP备11043737号-1 程序:Discuz! x3.4

湘公网安备 43018102000145号

手机版|Archiver|蓝色动力网络   

快速回复 返回顶部 返回列表