注册 | 登陆
浏览模式: 标准 | 列表全部文章

Nginx用作反向代理服务器

  Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过三年了。Igor 将源代码以类BSD许可证的形式发布。Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,大部分门户网站都把它作为首选WEB前端。

      下面讲讲如何利用Nginx的反向代理功能做一台反向代理服务器。

      一、安装步骤:

           (系统要求:Linux 2.6+ 内核,本文中的Linux操作系统为RedHat AS4为例)

         1、获取相关源程序

             wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz

             wget http://sysoev.ru/nginx/nginx-0.8.36.tar.gz

         2、创建相关目录和用户

             /usr/sbin/groupadd apache
            /usr/sbin/useradd -g apache apache

            /usr/sbin/usermod -s /sbin/nologin apache

            chage -I -1 -M 99999 apache

            mkdir -p /data/mp3 
            chmod +w /data/mp3

            chown -R apache:apache /data/mp3

         3、安装Nginx所需的pcre库

            tar zxvf pcre-8.01.tar.gz
     cd pcre-8.01/
    ./configure
            make && make install
            cd ../

         4、安装Nginx

           tar zxvf nginx-0.8.36.tar.gz
    cd nginx-0.8.36/
    ./configure --user=apache --group=apache --prefix=/usr/local/nginx --with-http_stub_status_module
    make && make install
    cd ../

         5、创建Nginx配置文件

            rm -f /usr/local/nginx/conf/nginx.conf
            vi /usr/local/nginx/conf/nginx.conf 

            输入以下内容:

           user  apache apache;
           worker_processes  8;

           error_log  /dev/null  crit;
           pid logs/nginx.pid;

           events {
                        use epoll;
                        worker_connections  512000;
                     }

           http {
                   include       mime.types;
                   default_type  application/octet-stream;

                   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                   '$status $body_bytes_sent "$http_referer" '
                   '"$http_user_agent" "$http_x_forwarded_for"';

                   access_log  /var/log/nginx_mp3.log  main;

                   sendfile       on;
                   tcp_nopush     on;
                   tcp_nodelay    on;

                   keepalive_timeout  650;
                   server {
                             listen       80;
                             server_name  xxx.xxx.xxx;   #前端域名或IP
                             location ~ .*\.(mp3|mid|amr)$
                            {
                                  expires 15d;
                                  root /data/mp3;
                                  proxy_store on;
                                  proxy_store_access user:rw group:rw all:rw;
                                  proxy_temp_path /data/mp3;
                                  proxy_redirect          off;
                                  proxy_set_header        Host xxx.xxx.xxx ; #访问域名或ip
                                  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 1280k;
                                  proxy_connect_timeout   900;
                                  proxy_send_timeout      900;
                                  proxy_read_timeout      900;
                                  proxy_buffer_size       40k;
                                  proxy_buffers           40 320k;
                                  proxy_busy_buffers_size 640k;
                                  proxy_temp_file_write_size 640k;
                                  if ( !-e $request_filename)
                                 {
                                         proxy_pass  http://xxx.xxx.xxx.xx/; #后端服务器ip地址
                                 }
                            }
                       }
                  }
        6、启动Nginx

            ulimit -SHn 51200

            /usr/local/nginx/sbin/nginx -t    #测试配置脚本是否正确

           /usr/local/nginx/sbin/nginx


      二、优化Linux内核参数

          vi /etc/sysctl.conf

          在末尾增加以下内容:  

    # Add
    net.ipv4.tcp_max_syn_backlog = 65536
    net.core.netdev_max_backlog =  32768
    net.core.somaxconn = 32768

    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216

    net.ipv4.tcp_timestamps = 0
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_syn_retries = 2

    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_tw_reuse = 1

    net.ipv4.tcp_mem = 94500000 915000000 927000000
    net.ipv4.tcp_max_orphans = 3276800

    net.ipv4.ip_local_port_range = 1024  65535
    net.ipv4.ip_conntrack_max = 6553600
    net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
    net.ipv4.tcp_window_scaling = 1

      

           使配置立即生效:

 

           /sbin/sysctl -p

 

      三、配置开机自动启动Nginx

          vi /etc/rc.local

          在末尾增加以下内容:

          ulimit -SHn 51200
          /usr/local/nginx/sbin/nginx

      

      另外根据需要还需设置IP地址、开放访问端口、以及访问日志的定时切割等。(全文完)     

 

贴几个日本的VPS

DH 9.24$ coupon

Save over $110 on web hosting and receive unlimited disk space and bandwidth!
Sign up today for a risk-free trial of a one-year hosting plan using the promotional code "777bday11" and you'll get an entire year of web hosting (including a domain registration) for just $9.24! That's 92% off our normal pricing!

注册地址 www.dreamhost.com

图片附件(缩略图):
大小: 111.73 K
尺寸: 500 x 322
浏览: 0 次
点击打开新窗口浏览全图

godaddy 1$注册玉米

cool1
SPECIAL OFFER! $1.00 DOMAIN NAME! Register any available .COM, .US, .MOBI, .BIZ, .NET, .ORG, .CA, .CO.UK and .IN domain for just $1.00!*

Applies to the first year only of new registrations. This offer may not be used for renewals, transfers, bulk registrations, premium domains or Sunrise/Landrush domain registrations. Limited to one order per customer, expiring after 10,000 redemptions or at 11:59 PM on October 30, 2011 (whichever comes first). Discount will be reflected in your shopping cart; cannot be used in conjunction with any other offer or promotion. Customers may not use gift cards, PayPal® or AliPay to redeem this offer. * Plus ICANN fee of 18 cents per domain year when applicable. Your discount will be applied in your shopping cart.

godaddy 任意訂單優惠31%優惠碼, 其他有效優惠碼集合

無最低消費限制的
gdz952c
gdz952g
gdz952r
任意訂單優惠31%

其他一些godaddy優惠碼
$7.49 .COMs FAN3  
$7.49 .ORGs FAN749  
$7.49 .NETs YUP749  
$7.49 .BIZs FED749

$12.99 SSL優惠碼 MINSSL

$7.99 .INFOs 續費 gdbb776, GDBBREN8
$7.49 .ORGs/.NETs 註冊續費, cwm7
$7.49 .COMs 續費, OK412

linode 开设东京机房

http://www.linode.com/

价格和美国的一样,对亚洲用户访问来说还是不错的

Deploy your Linode cloud servers worldwide, including our newest facility in Tokyo, Japan.

硬盘测试

dd if=/dev/zero of=test bs=64k count=16k conv=fsync
16384+0 records in
16384+0 records out
1073741824 bytes (1.1 GB) copied, 17.943 s, 59.8 MB/s
dd if=/dev/zero of=test bs=64k count=2k oflag=dsync
2048+0 records in
2048+0 records out
134217728 bytes (134 MB) copied, 51.7045 s, 2.6 MB/s

buyvm 提供免费5G 备份空间

5GB Backup Storage
Unlimited domain hosting.
Limit: 1 per client.
Use as web hosting is prohibited!
Accounts with no VPS product ordering this will be deleted!

 

https://my.frantech.ca/cart.php

$15.00/year 256MB Virtual server in Chicago,IL

Dear ,

This is a courtesy e-mail to let you know we have free space in the Chicago,IL area and are looking to fill it.

We are offering the following plan in the Chicago,IL area for $15.00/year

Instant Setup!
Guaranteed RAM: 256MB
Burstable RAM: 512MB
Disk Space: 10GB
Bandwidth: 500GB/Month
Fair Share CPU
1 IP Address
SolusVM Control Panel

$15.00/year (USD)

This above plan can not be migrated under any circumstances to our Dallas,TX area or any other location that may become available.

The order link for the above plan is below (Direct Link):

https://123systems.net/billing/cart.php?a=add&pid=92

This is an limited time plan and stock is subject to expire at any time. Once stock has expired on this plan then it will no longer be available in the future. Get it while it is still available!

If you no longer wish to receive e-mails from our company please e-mail abuse[at]123systems.net requesting your immediate removal.

Warm Regards,

Copyright 2009-2011 ©
123Systems Solutions™