测试版本nginx1.6.3
测试系统:centos 6系统
安装配置文档:http://jasonzhu.blog.51cto.com/5594807/1750188
原理:
用户发出访问请求,域名解析到nginx服务器的ip(23.234.xx.2),在nginx服务器配置ip反向代理,将xx.2收到的请求,通过代理转发规则,统统转发给23.234.xx.3
用户---(请求,域名解析ip)--->抗攻击(nginx转发服务器)---(代理转发规则)-->后端apache服务器
ip反向代理配置:
vim /usr/local/nginx/conf/nginx.conf
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;
include /usr/local/nginx/conf/conf.d/*.conf;
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://$target;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#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;
}
}
在/usr/local/nginx/conf/目录下创建conf.d/map.conf扩展转发规则
vim /usr/local/nginx/conf/conf.d/map.conf
map $server_addr $target {
#baidu.com
23.234.xx.2 23.234.xx.3:80;
#请求IP 转发IP:端口
}
PS:target参数传到nginx.conf配置文件中,作为下一跳转发的地址。
/usr/local/nginx/sbin/nginx -s reload 重新加载配置文件