使用Nginx/Lighttpd/Squid作为反向代理服务器 - [技术笔记]

使用Nginx/Lighttpd作为反向代理服务器 - [技术笔记]

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://iyubo.blogbus.com/logs/23556978.html

反向代理服务已经越来越广泛的应用于高负载的Web站点中,常用来作为Reverse Proxy的有Squid、Apache、Lighttpd、Nginx等,后两个轻量级的应用因为其优秀的表现已迅速占领了大量市场,本文只讨论后两者的简单应用(用proxy处理静态文件而把动态文件交给后端的Web服务器来处理)
安装环境
操作系统: Debian 4.0 r3
Kernel: 2.6.18-6-686
软件列表
nginx-0.6.31.tar.gz
lighttpd-1.4.19.tar.gz
安装过程
安装nginx作为反向代理
# tar zxvf nginx-0.6.31.tar.gz
# cd nginx-0.6.31
# ./configure --prefix=/usr/local/nginx --with-http_realip_module
# make && make install
# vi /usr/local/nginx/conf/nginx.conf
        location / {
            proxy_pass         http://10.10.10.87/;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
#           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;;

            client_max_body_size       10m;
            client_body_buffer_size    128k;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }

        # Static files location
        location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|htm|html)$ {
            root   /srv/www/htdocs/;
        }

启动nginx
# /usr/local/nginx/sbin/nginx

安装lighttpd作为反向代理
# tar zxvf lighttpd-1.4.19.tar.gz
# cd lighttpd-1.4.19
# ./configure --prefix=/usr/loca/lighttpd --without-bzip2
# make && make install
# cp doc/lighttpd.conf /etc/lighttpd.conf
# vi /etc/lighttpd.conf

server.modules              = (
                                "mod_access",
                                "mod_status",
                                "mod_proxy",
                                "mod_accesslog" )

server.document-root        = "/srv/www/htdocs/"

server.errorlog             = "/var/log/lighttpd/error.log"

status.status-url = "/server-status"

$HTTP["url"] !~ "/.(js|css|gif|jpg|png|ico|txt|swf|html|htm)$" {
     proxy.server  = ( "" => (
     ( "host" => "10.10.10.87", "port" => 80 )
      )
    )
}

启动lighttpd
# /usr/local/lighttpd/sbin/lighttpd -f /etc/lighttpd.conf

参考文档
http://www.mysqlperformanceblog.com/2008/06/17/lighttpd-as-reverse-proxy/
http://blog.kovyrin.net/2006/05/18/nginx-as-reverse-proxy/
http://www.mysqlperformanceblog.com/2006/05/21/speedup-your-lamp-stack-with-lighttpd/

http://blog.kovyrin.net/2006/04/17/typical-nginx-configurations/
===========================================================
windows下简单配置squid反向代理服务器
下载windwosNT版本的squid下载地址:

http://squid.acmeconsulting.it/download/squid-2.6.STABLE13-bin.zip

1.把squid-2.6.STABLE13-bin.zip解压缩,把里面的squid文件夹拷到c:/下(squid默认的是c:/squid)
2.squid/etc目录下把
squid.conf.default拷贝一份重新命名为squid.conf
cachemgr.conf.default拷贝一份重新命名为cachemgr.conf
mime.conf.default拷贝一份重新命名为mime.conf
3.用文本编辑器打开squid.conf,需要修改的地方:
找到http_port 3128在后面增加一行
http_port 80 transparent
找到#cache_peer sib2.foo.net sibling 3128 3130 [proxy-only]在后面增加一行
cache_peer 192.168.1.8 parent 7001 0 no-query originserver
找到# TAG: visible_hostname在后面增加一行
visible_hostname volcano(任意命名)
找到http_access deny all在其前面加#将这一行注释掉,然后增加一行
http_access allow all

4.从命令行到c:/squid/sbin目录下执行
squid -i(将squid服务加入到服务里面)
squid -z
安装完成

5.从服务里启动squid
访问squid服务器:
http://192.168.1.2(你的squid服务器IP地址)>>>指向http://192.168.1.8:7001(web服务器地址)
如果把#http_access deny all打开把http_access allow all注释掉,你的访问就会被拒绝
你需要配置一下:找到下面两行
#acl our_networks src 192.168.1.0/24 192.168.2.0/24
#http_access allow our_networks
打开注释,修改你的内网ip(段)可以设为192.168.1.0/24一个也可以如上面的一样设一段IP

 ===================================================================

附:反向代理原理图

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值