nginx反向代理

 

配置参数

proxy_pass; 
# 用来设置将客户端请求转发给的后端服务器的主机,可以是主机名、IP 地址:端口的方式,也可以代理到预先设 置的主机群组,需要模块gx_http_upstream_module支持。
 
location /web {    
  index index.html;    
  proxy_pass http://192.168.7.103:80;     
# 不带斜线将访问的 /web,等于访问后端服务器 
 http://192.168.7.103:80/web/index.html,即后端 服务器配置的站点根目录要有 web 目录才可以被访问,这是一个追加 /web 到后端服务器 
 http://servername:port/WEB/INDEX.HTML 的操作
 
proxy_hide_header; 
# 用于nginx作为反向代理的时候,在返回给客户端http响应的时候,隐藏后端服务版本相应头部的信息,可以设置 在 http/server 或 location 块: 
location /web {    
  index index.html;    
  proxy_pass http://192.168.7.103:80/;     
  proxy_hide_header ETag; 
}

proxy_pass_request_body on | off; 
# 是否向后端服务器发送HTTP包体部分,可以设置在 http/server 或 location 块,默认即为开启

proxy_pass_request_headers on | off; 
# 是否将客户端的请求头部转发给后端服务器,可以设置在 http/server 或 location 块,默认即为开启

proxy_set_header; 
# 可以更改或添加客户端的请求头部信息内容并转发至后端服务器,比如在后端服务器想要获取客户端的真实IP的时 候,就要更改每一个报文的头部,如下:
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
#proxy_set_header HOST  $remote_addr;   
# 添加HOST到报文头部,如果客户端为 NAT 上网那么其值为客户端的共用的公网 IP 地址。

proxy_hide_header field; 
# 用于隐藏后端服务器特定的响应首部,默认 nginx 在响应报文中不传递后端服务器的首部字段 Date, Server, XPad,  X-Accel 等

proxy_connect_timeout time; 
# 配置 nginx 服务器与后端服务器尝试建立连接的超时时间,默认为 60 秒,用法如下: 
proxy_connect_timeout 60s; 
# 60s 为自定义 nginx 与后端服务器建立连接的超时时间

proxy_read_time time; 
# 配置 nginx 服务器向后端服务器或服务器组发起 read 请求后,等待的超时时间,默认 60s 
proxy_send_time time;
# 配置 nginx 项后端服务器或服务器组发起 write 请求后,等待的超时时间,默认 60s

proxy_http_version 1.0; 
# 用于设置 nginx 提供代理服务的 HTTP 协议的版本,默认 http 1.0

proxy_ignore_client_abort off; 
# 当客户端网络中断请求时,nginx 服务器中断其对后端服务器的请求。即如果此项设置为 on 开启,则服务器会忽略客户端中断并一直等着代理服务执行返回,如果设置为 off ,则客户端中断后 Nginx 也会中断客户端请求并立即记录 499 日志,默认为 off。

proxy_headers_hash_bucket_size 64; 
# 当配置了 proxy_hide_header 和 proxy_set_header 的时候,用于设置 nginx 保存 HTTP 报文头的 hash 表的上 限。 
proxy_headers_hash_max_size 512; 
# 设置 proxy_headers_hash_bucket_size 的大可用空间 
server_namse_hash_bucket_size 512; 
# server_name hash 表申请空间大小 
server_names_hash_max_szie   512;  
# 设置服务器名称hash表的上限大小

  

buffer设置

 

posted @ 2019-12-06 16:22  jabbok  阅读(227)  评论(0编辑  收藏  举报