网站建设提供源代码有什么用,英语网站都可以做哪些内容,上传到服务器的网站打开是空白,网站开发所涉及的技术Nginx反向代理的配置语法 Nginx反向代理模块的指令是由ngx_http_proxy_module模块进行解析 proxy_pass
该指令用来设置被代理服务器地址#xff0c;可以是主机名称、IP地址加端口号形式。
语法proxy_pass URL;默认值—位置location
URL:为要设置的被代理服务器地址#xf…Nginx反向代理的配置语法 Nginx反向代理模块的指令是由ngx_http_proxy_module模块进行解析 proxy_pass
该指令用来设置被代理服务器地址可以是主机名称、IP地址加端口号形式。
语法proxy_pass URL;默认值—位置location
URL:为要设置的被代理服务器地址包含传输协议(http,https://)、主机名称或IP地址加端口号、URI等要素。
proxy_pass后面的值要不要加/?
server {listen 80;server_name localhost;location /{#proxy_pass http://192.168.200.146;proxy_pass http://192.168.200.146/;}
}
当客户端访问 http://localhost/index.html,效果是一样的
server{listen 80;server_name localhost;location /server{#proxy_pass http://192.168.200.146;proxy_pass http://192.168.200.146/;}
}
当客户端访问 http://localhost/server/index.html
这个时候第一个proxy_pass就变成了http://localhost/server/index.html
第二个proxy_pass就变成了http://localhost/index.html效果就不一样了。proxy_set_header
该指令可以更改Nginx服务器接收到的客户端请求的请求头信息然后将新的请求头发送给代理的服务器
语法proxy_set_header field value;默认值proxy_set_header Host $proxy_host;proxy_set_header Connection close;位置http、server、location
需要注意的是如果想要看到结果必须在被代理的服务器上来获取添加的头信息。
被代理服务器 [192.168.200.146]
server {listen 8080;server_name localhost;default_type text/plain;return 200 $http_username;
}代理服务器: [192.168.200.133]
server {listen 8080;server_name localhost;location /server {proxy_pass http://192.168.200.146:8080/;proxy_set_header username TOM;}
}
proxy_redirect
该指令是用来重置头信息中的Location和Refresh的值。
语法proxy_redirect redirect replacement;proxy_redirect default;proxy_redirect off;默认值proxy_redirect default;位置http、server、location
》为什么要用该指令?
服务端[192.168.200.146]
server {listen 8081;server_name localhost;if (!-f $request_filename){return 302 http://192.168.200.146;}
}
代理服务端[192.168.200.133]
server {listen 8081;server_name localhost;location / {proxy_pass http://192.168.200.146:8081/;proxy_redirect http://192.168.200.146 http://192.168.200.133;}
}该指令的几组选项
proxy_redirect redirect replacement;
redirect:目标,Location的值
replacement:要替换的值proxy_redirect default;
default;
将location块的uri变量作为replacement,
将proxy_pass变量作为redirect进行替换proxy_redirect off;
关闭proxy_redirect的功能Nginx反向代理实战
服务器1,2,3存在两种情况
第一种情况: 三台服务器的内容不一样。
第二种情况: 三台服务器的内容是一样。如果服务器1、服务器2和服务器3的内容不一样那我们可以根据用户请求来分发到不同的服务器。
代理服务器
server {listen 8082;server_name localhost;location /server1 {proxy_pass http://192.168.200.146:9001/;}location /server2 {proxy_pass http://192.168.200.146:9002/;}location /server3 {proxy_pass http://192.168.200.146:9003/;}
}服务端
server1
server {listen 9001;server_name localhost;default_type text/html;return 200 h1192.168.200.146:9001/h1
}
server2
server {listen 9002;server_name localhost;default_type text/html;return 200 h1192.168.200.146:9002/h1
}
server3
server {listen 9003;server_name localhost;default_type text/html;return 200 h1192.168.200.146:9003/h1
}反向代理系统调优
反向代理值Buffer和Cache
Buffer翻译过来是缓冲Cache翻译过来是缓存。
总结下 相同点: 两种方式都是用来提供IO吞吐效率都是用来提升Nginx代理的性能。 不同点: 缓冲主要用来解决不同设备之间数据传递速度不一致导致的性能低的问题缓冲中的数据一旦此次操作完成后就可以删除。 缓存主要是备份将被代理服务器的数据缓存一份到代理服务器这样的话客户端再次获取相同数据的时候就只需要从代理服务器上获取效率较高缓存中的数据可以重复使用只有满足特定条件才会删除. 1Proxy Buffer相关指令
》proxy_buffering :该指令用来开启或者关闭代理服务器的缓冲区
语法proxy_buffering on|off;默认值proxy_buffering on;位置http、server、location
》proxy_buffers:该指令用来指定单个连接从代理服务器读取响应的缓存区的个数和大小。
语法proxy_buffers number size;默认值proxy_buffers 8 4k | 8K;(与系统平台有关)位置http、server、location
number:缓冲区的个数
size:每个缓冲区的大小缓冲区的总大小就是number*size
》proxy_buffer_size:该指令用来设置从被代理服务器获取的第一部分响应数据的大小。保持与proxy_buffers中的size一致即可当然也可以更小。
语法proxy_buffer_size size;默认值proxy_buffer_size 4k | 8k;(与系统平台有关)位置http、server、location
》proxy_busy_buffers_size该指令用来限制同时处于BUSY状态的缓冲总大小。
语法proxy_busy_buffers_size size;默认值proxy_busy_buffers_size 8k|16K;位置http、server、location
》proxy_temp_path:当缓冲区存满后仍未被Nginx服务器完全接受响应数据就会被临时存放在磁盘文件上该指令设置文件路径
语法proxy_temp_path path;默认值proxy_temp_path proxy_temp;位置http、server、location
注意path最多设置三层。
》proxy_temp_file_write_size该指令用来设置磁盘上缓冲文件的大小。
语法proxy_temp_file_write_size size;默认值proxy_temp_file_write_size 8K|16K;位置http、server、location
通用网站的配置
proxy_buffering on;
proxy_buffer_size 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;根据项目的具体内容进行相应的调节。