|
大陆的网络环境,都在天朝神兽的制度下让我等小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 |
3389, 打印机, 诺德尔, 网吧, 网吧版, 网吧系统, ndeer, 极速版, 诺德尔, 极速版, 诺德尔, QQ空间, QQ签名, QQ空间, QQ签名, 绿茶, QQ签名, 服务器, 论坛, 3389, 免费, 3389, 打印机, 主机, QQ空间, QQ签名, 矮哨兵, 网吧, ta
|