nginx配置

1.nginx主配置文件nginx.conf。 javascript

# 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  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
    use epoll;
    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  60;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 3;
    gzip_types text/plain text/javascript application/javascript application/x-javascript application/json text/css application/xml;
    gzip_vary on;
	#/etc/cache 緩存目錄,沒生成一個緩存,都會產生一個緩存文件
	proxy_temp_path /etc/temp_dir;
	proxy_cache_path /etc/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;

    upstream appsrvs {
        ip_hash;
        server 10.168.100.223:80 max_fails=3 fail_timeout=5s;
        server 10.168.100.224:80 max_fails=3 fail_timeout=5s;
    }
    server_names_hash_bucket_size 128;
    include /etc/nginx/conf.d/*.conf; }

2./etc/nginx/conf.d/目錄下,部分主配置文件appsrvs.conf: css

server {
    listen 80;
    server_name 10.168.100.222; #域名或者服務器ip
    index index.jsp index.htm index.html;
	
	
	proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
	proxy_redirect off;
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	client_max_body_size 1000m;
	client_body_buffer_size 128k;
	proxy_connect_timeout 90;
	proxy_send_timeout 90;
	proxy_read_timeout 90;
	proxy_buffer_size 4k;
	proxy_buffers 4 32k;
	proxy_busy_buffers_size 64k;
	proxy_temp_file_write_size 64k;
	
	proxy_cache_key		$host$uri$is_args$args;
	proxy_cache cache_one;
	proxy_cache_valid	200 304 302 24h;
	proxy_cache_valid    301 3d;
	proxy_cache_valid    any 1m;
	
	log_format cache '***$time_local '  '***$upstream_cache_status '  '***Cache-Control: $upstream_http_cache_control ' '***Expires: $upstream_http_expires ' '***"$request" ($status) ' '***"$http_user_agent" ';  
        access_log  /var/log/nginx/cache.log cache;
	#/var/log/nginx/cache.log 記錄緩存的log,每次請求都會生產一條記錄,其中出現***MISS **表示緩存沒有命中,***HIT **表示命中緩存。
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #請求的過濾規則
	{
		proxy_pass http://appsrvs; #一般對應是tomcat地址
		
		expires 5d;
	}
	
	#location ~ .*\.(css|js)$
	#{
		#proxy_pass http://appsrvs;
		
		#expires 3h;
	#}
	
	
    location / {
		proxy_pass http://appsrvs;
    }
	
}
相關文章
相關標籤/搜索