向上游服务建立联系
Syntax: proxy_connect_timeout time; #设置TCP三次握手超时时间,默认60秒;默认超时后报502错误
Default: proxy_connect_timeout 60s;
Context: http, server, location
超时更换上游服务器处理请求
Syntax: proxy_next_upstream http_502 | ..;
Default: proxy_next_upstream error timeout;
Context: http, server, location
上游连接启用TCP keepalive的长连接
Syntax: proxy_socket_keepalive on | off;
Default: proxy_socket_keepalive off;
Context: http, server, location
上游连接启用http长连接
Syntax: keepalive connections;
Default: —
Context: upstream Syntax: keepalive_requests number;
Default: keepalive_requests 100;
Context: upstream
修改tcp连接中的local address
Syntax: proxy_bind address [transparent] | off;
Default: —
Context: http, server, location 可以使用的变量
proxy_bind $remote_addr;
可以使用不属于所在机器的IP
proxy_bind $remote_addr transparent;
当客户端关闭连接时
Syntax: proxy_ignore_client_abort on | off;
Default: proxy_ignore_client_abort off;
Context: http, server, location
向上游服务发送HTTP请求;超时时间
Syntax: proxy_send_timeout time;
Default: proxy_send_timeout 60s;
Context: http, server, location
接收上游服务器HTTP响应头部
Syntax: proxy_buffer_size size; #设置接收上游服务的头部最大值
Default: proxy_buffer_size 4k|8k;
Context: http, server, location
接收上游服务器HTTP包体大小
Syntax: proxy_buffers number size; # 接收上游服务器响应包大小内存设置
Default: proxy_buffers 8 4k|8k;
Context: http, server, location
接收上游服务器的包体
Syntax: proxy_buffering on | off; X-Accel-Buffering 头部
Default: proxy_buffering on; #接收完完整的响应包在在响应给客户端
Context: http, server, location Syntax: proxy_max_temp_file_size size; #设之上游服务器响应包过大,后存入磁盘文件。文件大小的设置
Default: proxy_max_temp_file_size 1024m;
Context: http, server, location Syntax: proxy_temp_file_write_size size; # 每一次向磁盘写入的字节数
Default: proxy_temp_file_write_size 8k|16k;
Context: http, server, location Syntax: proxy_temp_path path [level1 [level2 [level3]]];# 设置存储文件的目录的路径
Default: proxy_temp_path proxy_temp;
Context: http, server, location
及时转发的包体
Syntax: proxy_busy_buffers_size size; #虽然设置缓存上游服务器的响应报文;但也可以接缓存一部分时就发送给客户
Default: proxy_busy_buffers_size 8k|16k;
Context: http, server, location
接收上游服务器网络速率相关指令
Syntax: proxy_read_timeout time; #两次读取超时时间
Default: proxy_read_timeout 60s;
Context: http, server, location Syntax: proxy_limit_rate rate; #限制读取上游服务的响应
Default: proxy_limit_rate 0;
Context: http, server, location
上游包体的持久化
Syntax: proxy_store_access users:permissions ...; #从上游服务接收文件存入本地文件权限的配置方法
Default: proxy_store_access user:rw;
Context: http, server, location Syntax: proxy_store on | off | string; # on的话会存到root对应的目录下;off不开启,string通过变量重新指定存放目录
Default: proxy_store off;
Context: http, server, location
配置
[root@python vhast]# cat shangyou.conf
server {
listen 8011;
default_type text/plain;
return 200 '8011 server response.\n';
} server {
listen 8012;
default_type text/plain;
root html;
location /{
}
location /test { return 200 '8012 server response.
uri: $uri
method: $request_method
requset: $request
http_name: $http_name
\n';
}
} [root@python vhast]# cat proxy_method.conf upstream haha{
#ip_hash;
#hash user_$arg_username;
#server 127.0.0.1:8011;
server 127.0.0.1:8012;
#keepalive 32;
}
server {
server_name proxy_pass.com;
error_log rrups_error.log info;
proxy_set_header Connection "";
root /tmp;
location /{
#proxy_pass http://rrups/addurl;
proxy_pass http://haha;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
}
}
[root@python vhast]# echo "qwertyuopuughgbbvvbaaa" > ../../html/a.txt [root@python vhast]# ll /tmp/
总用量 0
drwx------. 3 root root 17 7月 5 12:35 systemd-private-1c111c1c3c844bb594508d0cf90d1752-chronyd.service-YE54pH
drwx------. 3 root root 17 7月 8 12:40 systemd-private-24aea6f6d72d4605a59e86dc56dacf2a-chronyd.service-1Ocoyt
drwx------. 3 root root 17 7月 9 12:05 systemd-private-d838c8aa5ea24b2d88e0e1c546dadbcf-chronyd.service-wNkAsB
测试
[root@python vhast]# curl proxy_pass.com/a.txt
qwertyuopuughgbbvvbaaa
[root@python vhast]# ll /tmp/
总用量 4
-rw-rw-r--. 1 nginx nginx 23 7月 12 22:07 a.txt
drwx------. 3 root root 17 7月 5 12:35 systemd-private-1c111c1c3c844bb594508d0cf90d1752-chronyd.service-YE54pH
drwx------. 3 root root 17 7月 8 12:40 systemd-private-24aea6f6d72d4605a59e86dc56dacf2a-chronyd.service-1Ocoyt
drwx------. 3 root root 17 7月 9 12:05 systemd-private-d838c8aa5ea24b2d88e0e1c546dadbcf-chronyd.service-wNkAsB