nginx常用配置使用

worker_processes  1;
worker_rlimit_nofile 65535;
events {
    worker_connections  1024;
}
http {   
	include   mime.types;
	default_type application/octet-stream;	
	log_format main ' $remote_user [$time_local]  $http_x_Forwarded_for $remote_addr $request '
					'$http_x_Forwarded_for '
					'$upstream_addr '
					'ups_resp_time: $upstream_response_time '
					'request_time: $request_time  host:$host';					
	access_log logs/access.log main;
	#error_log logs/error.log notice;
	#rewrite_log on;
	sendfile on;
	server_tokens off;
	keepalive_timeout 120;
	proxy_connect_timeout 2;
	proxy_send_timeout 2;
	proxy_read_timeout 4000;
	proxy_buffer_size 2k;
	gzip on;	
	proxy_set_header X-Real-Ip $remote_addr;
	proxy_set_header Host jwb.njtech.edu.cn;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header Referer http://jwb.njtech.edu.cn/;	
	proxy_cache_path cache keys_zone=one:100m max_size=10g inactive=365d;	
	upstream proxy_server {
		server 127.0.0.1:26435;
	}	
	upstream target_server {
		server jwb.njtech.edu.cn;
	}
    server {
        listen       80;
        server_name  127.0.0.1;
        location / {
			add_header Cache-Control no-cache;
            proxy_pass http://proxy_server;
        }
		#${PRELOCATIONS}
    }
	server {
        listen       26435;
        server_name  127.0.0.1;
		proxy_cache one;
		proxy_cache_methods GET POST HEAD;
		proxy_cache_key "$request_uri|$request_body";
		proxy_cache_valid 365d;
		proxy_ignore_headers Set-Cookie Cache-Control X-Accel-Expires Expires;
		add_header Nginx-Cache "$upstream_cache_status";
        location / {
            proxy_pass http://target_server;	
        }
		#${POSTLOCATIONS}
    }
	map $http_upgrade $connection_upgrade {
		default upgrade;
		''      close;
	}
}

posted @ 2019-10-27 17:20  小小tree  阅读(159)  评论(0)    收藏  举报