笔记:centos6 nginx反向代理

前端之家收集整理的这篇文章主要介绍了笔记: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

原文链接:https://www.f2er.com/centos/381152.html

猜你在找的CentOS相关文章