1、proxy
命令
proxy_pass url
(1)代理所有URI到后端服务器
location / {
proxy_pass http://192.168.49.142/;
}
(2)代理指定URL到后端服务器
location /test1/ {
proxy_pass http://192.168.49.142/test2/;
将请求/test1下面的资源都转到后端/test2/下的资源
location /test1 {
proxy_pass http://192.168.49.142;
将请求/test1/下面的资源都转到后端/test1/下的资源
proxy_set_header field value 设定向后端主机发送的请求报文的首部和值
(1)将客户端请求的真实IP转到后端apache服务器
location / {
proxy_pass http://192.168.49.142/;
proxy_set_header X-Real-IP $remote_addr;
;
(2)将客户端请求的真实IP转到后端nginx服务器
location / {
proxy_pass http://192.168.49.142;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
然后在后端服务器的日志格式中添加 $http_x_forwarded_for 字段
proxy_cache_path path [levels=levels] keys_zone=name:size [inactive=time] [max_size=size] 定义缓存,可用于http上下文
proxy_cache zone | off 调用缓存,默认为off
proxy_cache_key string 定义缓存键
proxy_cache_key $request_uri
proxy_cache_key $scheme$proxy_host$request_uri
proxy_cache_vaild [code...] time; 为不同的响应码设定其缓存的时长
proxy_cache_vaild 200 302 10m;
proxy_cache_vaild 404 1m;