(7) Nginx反代配置


AS版本对应的反代配置文件.选配项,流量过大的时候适当使用反代加速.

 

必须修改的地方为第31行  IP地址.

可根据反代VPS的硬盘大小修改第28行最后一个CACHE大小,默认10g硬盘空间.

 

默认情况下,这个文件位于 /etc/nginx/nginx.conf

 

 

user www-data;
worker_processes auto;
pid /var/run/nginx.pid;

events {
	worker_connections 1024;
	multi_accept off;
}



http {
	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	access_log off;
	error_log /var/log/nginx/error.log;

#	gzip on;
#	gzip_disable "msie6";

	proxy_cache_path /home/nginxcache levels=1:2 keys_zone=cache_one:128m inactive=3d max_size=10g;
	upstream as {
		keepalive 20000;
		server 真实服务器IP:80 weight=10 max_fails=0;
	}

	server
	{
		listen *:80 ;
		server_name default_server;

		proxy_cache_key $host$uri$is_args$args;
		proxy_cache cache_one;
		proxy_http_version 1.1;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $host;
		proxy_set_header Connection "";
		proxy_redirect off;

		location / {
			proxy_pass  http://as;
			proxy_cache_valid 200 304 1h;
			expires 1h;
		}

		location = / {
			proxy_pass  http://as;
			proxy_cache_valid 200 304 5m;
			expires 5m;
		}
		location ^~ /themes {
			proxy_pass  http://as;
			proxy_cache_valid 200 304 24h;
			expires 24h;
		}
		location ^~ /images {
			proxy_pass  http://as;
			proxy_cache_valid 200 304 30d;
			expires 30d;
		}

	}
}