51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nginx反向代理配置

1)Nginx安装

LB01: 10.0.0.5配置
[root@lb01 ~]# scp 10.0.0.7:/etc/yum.repos.d/nginx.repo /etc/yum.repos.d/

安装Nginx
[root@lb01 conf.d]# yum -y install nginx
配置Nginx
[root@lb01 conf.d]# cat proxy.conf
server {
listen 80;
server_name blog.baimei.com;

location / {
proxy_pass http://10.0.0.7:80;
}
}
[root@lb01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 conf.d]# systemctl restart nginx

windows修改HOSTS文件解析到10.0.0.5

配置携带头部和HTTP1.1长连接
proxy_set_header Host $http_host; # 携带头部信息
proxy_http_version 1.1; # 携带长链接

代理必须携带的参数及优化:
[root@lb01 conf.d]# cat proxy.conf
server {
listen 80;
server_name blog.baimei.com;

location / {
proxy_pass http://10.0.0.7:80;
proxy_set_header Host $http_host; # 携带头部信息
proxy_http_version 1.1; # 长连接
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 携带客户端IP

proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;

proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
}
}

赞(4)
未经允许不得转载:工具盒子 » nginx反向代理配置