0
点赞
收藏
分享

微信扫一扫

nginx配置例子

worker_processes  4;
events {
use epoll;
    worker_connections  10240;
}
http {
 
    include       mime.types;
 
    default_type  application/octet-stream;
 
     log_format  main  '$msec $remote_addr $http_userid $http_pid $http_reqid [$time_local] $upstream_addr "$request_uri" '
                      '$status $bytes_sent $request_time "$http_x__referer" "$http_accept" $http_x_update $upstream_cache_status';
 
    #access_log  logs/access.log  main buffer=1m;
    access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
#keep alive with requestproxy
    keepalive_timeout  3600;
    keepalive_requests 1000000;
    client_header_timeout 3600;
    #keepalive_timeout  65;
 
#nginx ignore headers with underscores by default
    underscores_in_headers    on;
 
#gzip config
    gzip  on;
#gzip_static on;
    gzip_min_length 2048;
    gzip_types *;
    gzip_proxied any;
 
open_file_cache max=5000 inactive=180;
    proxy_temp_path /tmp/proxy_temp_path;
    proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=cache_one:1000m inactive=1d max_size=6000m;
    proxy_connect_timeout 2000ms;
proxy_read_timeout 10s;
 
#cache key
    proxy_cache_key $uri$is_args$args[$http_accept][$http_accept_encoding];
 
 
    proxy_cache cache_one;
 
#set on specific location if needed
    proxy_cache_valid 30s;
 
    proxy_cache_use_stale error timeout updating http_500 http_404 http_504;
    proxy_next_upstream error timeout updating http_500 http_404 http_504;
    proxy_cache_bypass   $http_x_update $arg_no_cache $arg_nocache;
 
    proxy_http_version 1.1;
 
#set general response header
more_set_headers 'REQID: $http_reqid';
more_set_headers 'REQTIME: $http_reqtime';
    more_set_headers 'THREADID: $http_threadid';
 
# Forward the user's IP address to Backend
    proxy_set_header Host            $host;
    proxy_set_header X-Real-IP       $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
    upstream  www.dogs.com  {
 
               server   10.15.107.112:9089  weight=1;
 
               server   10.15.88.70:9089  weight=1;
 
       }
 
    server {
 
        listen       80;
 
        server_name  www.dogs.com;
 
        root /var/www/html;
 
        index index.html index.htm index.jsp;
 
        location / {
 
        proxy_pass        http://www.dogs.com;
 
        proxy_set_header   Host             $host;
 
        proxy_set_header   X-Real-IP        $remote_addr;
 
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 
        }
 
        location ~ .*.jsp$ {
 
        index index.jsp;
 
        proxy_pass http://localhost:8080;
 
        }
 
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
 
        expires      30d;
 
        }
 
        location ~ .*\.(js|css)?$ {
 
        expires      1h;
 
        }
 
        error_page   500 502 503 504  /50x.html;
 
        location = /50x.html {
 
            root   html;
 
        }
 
    }
}

举报

相关推荐

0 条评论