安装Nginx

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers



1、安装Nginx所需的pcre库:
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ../


2、安装Nginx
wget http://labs.frickle.com/files/ngx_cache_purge-1.0.tar.gz
tar zxvf ngx_cache_purge-1.0.tar.gz     (第三方可以指定清除缓存的模块)

tar zxvf nginx-1.0.5.tar.gz
cd nginx-1.0.5/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_cache_purge-1.0
make && make install
cd ../


典型的配置文件

user  nagios nagios;
worker_processes  1;

error_log  /usr/local/nginx/logs/nginx_error.log  crit;

#pid        logs/nginx.pid;


events {
     use epoll;
     worker_connections 65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '
                      '"$request" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #charset utf-8;  #最好让浏览器自己解析

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
     
    sendfile on;
    tcp_nopush     on;

    keepalive_timeout 60;

    tcp_nodelay on;

    client_body_buffer_size 512k;
    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    #注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
    #proxy_temp_path   /var/proxy_temp_dir;

    #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为1GB。
    #proxy_cache_path   /var/proxy_cache_dir   levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=1g;

    #backend_server服务器组,随机分配,失败则轮询
    upstream webs{         
        server 192.168.16.191 weight=1 max_fails=2 fail_timeout=30s;
    }

    limit_zone   one  $binary_remote_addr  10m;

    server {
        listen       88;
        #listen 80 default;
        server_name  192.168.0.162;
        index index.html index.htm index.php;

        root  /usr/local/apps/musicDownload;
        access_log  /usr/local/nginx/logs/log.log main;



        location /files/
        {
            limit_conn   one  1;  #限制在one中记录状态的每个IP只能发起一个并发连接
            limit_rate 20k;       #对每个连接限速20k. 注意,这里是对连接限速,而不是对IP限速
        }

        #以扩展名方式匹配静态文件 
        location ~* \.(mp3|apk)$  
        {  
        #valid_referers none blocked server_names baidu.com;
        valid_referers blocked server_names baidu.com;
            if ($invalid_referer) {return 403;}
            expires 24h;
        } 


        location /
{
            proxy_pass http://webs;
        }


        #设定查看Nginx状态的地址
        location /NginxStatus
        {
            stub_status             on;
            access_log              on;
            auth_basic              "NginxStatus";
            auth_basic_user_file    /usr/local/webserver/nginx/conf/htpasswd;
        }
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

你可能感兴趣的:(nginx,cache,gcc,Access,nagios)