nginx 의 perl 스 크 립 트 에 포 함 된 프로필 샘플


user  apache apache;

worker_processes 8;
pid        /opt/modules/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
        use epoll;
        worker_connections 65535;
}

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

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 300m;

        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;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        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   /opt/data/proxy_temp_dir;
        #  Web      cache_one,         200MB,1             ,         30GB。
        proxy_cache_path  /opt/data/proxy_cache_dir  levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=30g;

        log_format  main  '$request_uri,$status,$remote_addr,$http_x_forwarded_for,[$time_local],$body_bytes_sent';
        log_format  count  '$request_uri,$status,$http_x_forwarded_for,$remote_addr,[$time_local]';

        upstream storm_perl {
                server   192.168.1.87:8000 weight=1 max_fails=2 fail_timeout=30s;
                server   192.168.1.110:8000 weight=1 max_fails=2 fail_timeout=30s;
        }

        upstream backend_server {
                server   192.168.1.87:8080 weight=1 max_fails=2 fail_timeout=30s;
                server   192.168.1.110:8080 weight=1 max_fails=2 fail_timeout=30s;
        }


        perl_set $storm_key_new '
                use MIME::Base64::Perl;
                use URI::Escape;
                sub{
                        my $r = shift;
                        my $request_uri = $r->variable("request_uri");
                        my $query_uri = $r->unescape($request_uri);
                        
                        my $buffer = $query_uri;
                        my @pairs = split(/&/, $buffer);
                        foreach $pair (@pairs)
                        {
                                if($pair =~ /c=storm/i){
                                        $pair =~ s/c=//g;
                                        return $pair;
                                }
                        }
                }
        ';

        server
        {
                listen       80;
                server_name  storm.baofeng.net;
                index index.html index.htm index.php;
                root  /opt/baofeng-data/;
                
                location /
                {
                
                        expires 1h;
#                       add_header Cache-Control no-cache;
#                       add_header Cache-Control private;
                        
                        proxy_next_upstream http_502 http_504 error timeout invalid_header;
                        proxy_cache cache_one;
                        #    HTTP            
                        proxy_cache_valid  200 304 30d;
                        proxy_cache_valid  404 1m;
                        #   、URI、     Web   Key ,Nginx  Key   ,              
                        
                        proxy_cache_key $storm_key_new;
                        proxy_set_header Host  $host;
                        proxy_set_header X-Forwarded-For  $remote_addr;
                        proxy_pass http://storm_perl;

                        error_log  /opt/modules/nginx/logs/error.log crit;
                        access_log  /opt/modules/nginx/logs/access.log main;
                }

                location ~* ^/NginxStatus/? { 
                         stub_status on; #Nginx       
                         access_log off; 
                 } 
        }

        server
        {
                listen       8000;
                server_name  storm.baofeng.net;
                index index.html index.htm index.php;
                root  /opt/baofeng-data/;  

                set $memd 0;
                set $memcached_server "127.0.0.1:11211";

                location ~ .*\.(php|jsp|cgi)?
                {
                        perl 'sub {
                                use Cache::Memcached;
                                my $r = shift;
                                if($r->variable("memd")){
                                        my $memd = $r->variable("memd");
                                }
                                if(!$memd){
                                        $memd = new Cache::Memcached {"servers" => [$r->variable("memcached_server")],"debug" => 0,"compress_threshold" => 10_000};
                                        $r->variable("memd",$memd);
                                }

                                my $realkey = 0;
                                $realkey = $r->variable("storm_key_new");
                                my $stormbox = $memd->get($realkey);

                                if($stormbox){
                                        $r->send_http_header;
                                        $r->print($stormbox);
                                        return 200;
                                }else{
                                        return 404;
                                }
                        }';
                        error_page      404 500 502 503 504 = @get_storm;
                        access_log  /opt/modules/nginx/logs/log_mm.log count;
                }

                location @get_storm {
                        proxy_set_header Host  $host;
                        proxy_set_header X-Forwarded-For  $remote_addr;
                        proxy_pass http://backend_server;
                        access_log  /opt/modules/nginx/logs/log_db.log count;
                }
        }

                     
}

좋은 웹페이지 즐겨찾기