nginx 配置優化處理


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	# 開啓gzip
	gzip  on;
	# 啓用gzip壓縮的最小文件,小於設置值的文件將不會壓縮
	gzip_min_length 1k;
	# gzip 壓縮級別,1-10,數字越大壓縮的越好,也越佔用CPU時間。一般設置1和2
	gzip_comp_level 2;
	# 進行壓縮的文件類型。javascript有多種形式。其中的值可以在 mime.types 文件中找到。
	gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
	# 是否在http header中添加Vary: Accept-Encoding,建議開啓
	gzip_vary on;
	# 禁用IE 6 gzip
	gzip_disable "MSIE [1-6]\.";
	# 設置緩存路徑並且使用一塊最大100M的共享內存,用於硬盤上的文件索引,包括文件名和請求次數,每個文件在1天內若不活躍(無請求)則從硬盤上淘汰,硬盤緩存最大10G,滿了則根據LRU算法自動清除緩存。
	#proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=10g;
	proxy_temp_path  /nginx_cache/temp;
	proxy_cache_path /nginx_cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g;
	
	
	
	upstream localhost{

		#weigth參數表示權值,權值越高被分配到的機率越大

		#本機上的Squid開啓3128端口
		#server 127.0.0.1:8081 weight=6;
		
		#server 127.0.0.1:8082 weight=10;
		
		
		server 59.195.29.58:8080;

		server 59.195.29.58:80;
		
		server 59.195.29.24:8080;

		server 59.195.29.24:80;
		
		server 59.195.29.22:8080;

		server 59.195.29.22:80;
		
		server 59.195.29.68:8080;

		server 59.195.29.68:80;  
          

	}

    server {
        listen       80;
        server_name  localhost;
		#proxy_cache my_cache;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			root   html;
            index  index.html index.htm;
            proxy_pass http://localhost;
            proxy_redirect    off;  
            proxy_set_header Host  $host:$server_port;
            proxy_set_header X-Forwarded-For  $remote_addr; 
        }
		
		  #緩存相應的文件(靜態文件)  
		location ~ \.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {  
		 proxy_pass http://localhost;   #如果沒有緩存則通過proxy_pass轉向請求 
		 proxy_redirect off;  
		 proxy_set_header Host $host;  
		 proxy_cache cache_one;  
		 proxy_cache_valid 200 302 1h;                              #對不同的HTTP狀態碼設置不同的緩存時間,h小時,d天數  
		 proxy_cache_valid 301 1d;  
		 proxy_cache_valid any 1m;  
		 expires 30d;  
		 proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

		}


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # 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 ssl;
    #    server_name  localhost;

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

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章