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

来源:互联网 发布:南风知我意小说 编辑:程序博客网 时间:2024/05/20 18:01

配置文件下载路径:下载

配置文件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;pidsbin/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;sendfileon;tcp_nopushon; 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;  } 



原创粉丝点击