nginx 场景实践03 - 代理proxy_pass

客户端 -----> 代理 ------> 服务端

正向代理和反向代理

  • 正向代理 客户端 <-----> 代理 -----> 服务端
  • 反向代理 客户端 ------> 代理 <----> 服务端

区别在于代理的对象不一样,正向代理的是服务器,反向代理的是客户端。

Lunix:   netstat -luntp | grep nginx  #查看nginx监听的端口号

MAC:     netstat -lnat |grep LISTEN

代理配置:

正向代理

注意点:

1.增加dns解析resolver

2.增加无server_name名的server

3.proxy_pass指令

resolver 8.8.8.8;
 server {
	listen 8088;
	location / {
		proxy_pass http://$http_host$request_uri;
	}
 }

反向代理

location /proxy/ {
    proxy_pass http://127.0.0.1:9000/;
}

其他配置参数

该指令开启从后端被代理服务器的响应内容缓冲.如果缓冲区开启,nginx假定被代理的后端服务器会以最快速度响应,并把内容保存在由指令。

proxy_buffering

语法: proxy_buffering on|off

默认值: proxy_buffering on

上下文: http, server, location

扩展 : proxy_buffer_size 、 proxy_buffer_size 、proxy_buffers

重定向301

proxy_redirect

语法: proxy_redirect [ default|off|redirect replacement ]

默认值: proxy_redirect default

上下文: http, server, location

头信息配置

proxy_set_header

语法: proxy_set_header header value

默认值: Host and Connection

上下文: http, server, location

## 配置
proxy_set_header Host $proxy_host;
proxy_set_header Connection Close;

超时time_out

proxy_connect_timeout
 
语法: proxy_connect_timeout timeout_in_seconds
 
上下文: http, server, location
 
 
proxy_read_timeout
 
语法: proxy_read_timeout the_time

默认值: proxy_read_timeout 60

上下文: http, server, location
发布了98 篇原创文章 · 获赞 185 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/xuezhiwu001/article/details/96826277
今日推荐