安装与web服务器一致
Nginx反向代理模块:http://Nginx.org/en/docs/
1、ngx_upsream module
2、ngx_http_proxy module
Nginx.conf配置在http内
cat >Nginx.conf<< eof
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
upstream server_pools{
server 192.168.137.8:80;
server 192.168.137.9:80;
}
include /application/Nginx/conf/extra/*.conf;
}
eof
配置反向代理
mkdir -p /application/Nginx/conf/extra &&\
touch /application/Nginx/conf/extra/lb.conf &&\
cat > /application/Nginx/conf/extra/lb.conf << eof
server {
listen 192.168.137.4:80;
server_name bbs.test.com;
location / {
proxy_pass http://server_pools;
proxy_set_header Host \$host;
proxy_set_header X-Real-Ip \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr;
}
}
eof
Nginx里记录X-Forwarder-For真实来源地址
apache需要在日志格式里添加\"${X-Forwarded-For}\"
利用VIP是为了方便迁移切换,业务尽量用虚拟IP
原文链接:https://www.f2er.com/centos/381152.html