nginx代理配置

1、下载nginx
 rpm包:http://nginx.org/packages/centos/5/x86_64/RPMS/nginx-1.6.3-1.el5.ngx.x86_64.rpm
 源码包:http://nginx.org/download/nginx-1.6.3.tar.gz
 
2、安装nginx
rpm -ivh nginx-1.6.3-1.el5.ngx.x86_64.rpm
编译安装:
#./configure -without-http_rewrite_module
#make
#make install


3、修改nginx配置参数

#vi /etc/nginx/nginx.conf
rpm安装的配置文件

#vi /usr/local/nginx/conf/nginx.conf
源码安装的配置文件

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;

}


http {
    include       /etc/nginx/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/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

   # keepalive_timeout  0;
   # keepalive_timeout  65;

    #gzip  on;
    
    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    #include /etc/nginx/conf.d/*.conf;
    upstream test.net{
       定义后端主机组
       server 195.203.xx.xx:7001;
       server 195.203.xx.xx:7001;
       keepalive 8;
       //开启长连接,8为连接数
     }

    server {
        listen       80;
        务器端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm index.php;
            proxy_pass   http://test.net;
            //读取分发组
            proxy_http_version 1.1;
            //http1.1支持长连接
            proxy_set_header host $remote_addr;
            proxy_set_header Connection "";
            //开启客户端IP转发
        }

       location /nginx-status {

             auth_basic              "NginxStatus";

         #    allow 192.168.2.0/24;

         #    deny all;

             stub_status on;

             access_log  on;

#             auth_basic_user_file    /usr/local/nginx/conf/htpasswd;

        }
    }
}

4、重启nginx
# service nginx restart
rpm安装重启方式

#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
源码安装重启方式

5、测试
#netstat -na | grep 7001
在后端服务器上执行,查看长连接状态及连接数

posted @ 2015-10-24 17:09  W&L  阅读(143)  评论(0编辑  收藏  举报