筆記:centos6 nginx反向代理

安裝與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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章