nginx根据客户端ip进行简单转发(回发)

本文详细介绍了Nginx服务器的配置文件内容,包括日志格式定义、代理设置、缓存路径配置等关键部分。通过具体示例展示了如何进行IP地址匹配、请求转发及PHP文件处理等操作。

配置文件下载路径:下载

配置文件default.vhosts.conf:

log_format ie '$remote_addr [$time_local:$msec] "POST $request_uri&$request_body HTTP/1.0" "$http_referer" "$http_user_agent"';
log_format customed_ie '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
server
{
	include vhosts/vhosts.listen.addr;
        if ($remote_addr ~* "10.11.202.181")
        {      
       		rewrite ^/(.*) http://$remote_addr:8080/$1;                 #根据ip匹配,回发给自己
        } 

	location ~ ^/post 
	{
		proxy_pass http://localhost:9999;
		access_log logs/ie_access_log ie;                           #记录日志
	}

	location = /q 
	{
		proxy_pass http://localhost:9999;
		access_log logs/ie_access_log ie;                           #记录日志
	}


	location ~ .*\.php$
	{
		include fastcgi.conf;

		fastcgi_pass localhost:9000;
		fastcgi_index index.php;
		access_log logs/getrank_access_log ie;                      #记录日志
	}

	location /
	{
		access_log logs/ie_access_log customed_ie;                   #记录日志
	}

}
配置文件nginx.conf:
user  nobody nobody;
worker_processes  8;
working_directory /search/nginx/core;
worker_rlimit_core 2G;


#error_log  logs/error.log error;
error_log  logs/error.log debug;


pid	sbin/nginx.pid;
worker_rlimit_nofile 51200;


events 
{
	use epoll;
	worker_connections  51200;
}


http 
{
	include	   mime.types;
	default_type  application/octet-stream;
	
	set_real_ip_from   10.15.4.0/24;
        set_real_ip_from   10.12.0.0/16;
        set_real_ip_from   10.11.0.0/16;
        set_real_ip_from   10.10.0.0/16;
        set_real_ip_from   10.14.0.0/16;
        set_real_ip_from   10.13.0.0/16;
	


        real_ip_header     X-Real-IP;
	include xnet.conf;


	log_format  main  '$remote_addr - $remote_user [$time_local] $request '
					  '"$status" $body_bytes_sent $request_time "$http_referer" '
					  '"$http_user_agent" "$http_x_forwarded_for"';
	log_format mini '$time_local $status $body_bytes_sent $request_time $upstream_cache_status $server_name';
        access_log logs/access_log main;
        access_log logs/status_log mini;
	
	server_names_hash_bucket_size 128;
	client_header_buffer_size 32k;
	large_client_header_buffers 4 32k;
	client_max_body_size 20m;


	sendfile	on;
	tcp_nopush	on;
 	tcp_nodelay on;


	#keepalive_timeout  30;
	send_timeout	   300;


	proxy_next_upstream error timeout;
        proxy_connect_timeout 2;
        proxy_read_timeout 5;
	
	#fastcgi_connect_timeout 300;
	#fastcgi_send_timeout 300;
	#fastcgi_read_timeout 300;
	#fastcgi_buffer_size 64k;
	#fastcgi_buffers 4 64k;
	#fastcgi_busy_buffers_size 128k;
	#fastcgi_temp_file_write_size 128k;


	#gzip  on;
	proxy_cache_path /dev/shm/nginx/cache2/ levels=2:2 keys_zone=sogou-cache2:154m max_size=1g inactive=24h ;


        proxy_cache_path /dev/shm/nginx/cache/ levels=2:2 keys_zone=sogou-cache:308m max_size=3g inactive=72h ;
        proxy_temp_path /dev/shm/nginx/temp/;


        fastcgi_cache_path /search/nginx/fastcgi_cache/ levels=2:2 keys_zone=sogou-fccache:128m max_size=4g inactive=72h ;
        fastcgi_temp_path /search/nginx/fastcgi_temp/;




	include vhosts/*.conf;
  
} 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值