当前位置: 首页 > news >正文

Nginx的反向代理、动静分离、负载均衡

反向代理

反向代理是一种常见的网络技术,它可以将客户端的请求转发到服务器群集中的一个或多个后端服务器上进行处理,并将响应结果返回给客户端。反向代理技术通常用于提高网站的可伸缩性和可用性,并且可以隐藏真实的后端服务器地址。


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;# gzip on;server {listen 80;server_name localhost;#默认编码charset utf-8;# access_log logs/host.access.log  main;location / {#反向代理的urlproxy_pass http://www.baidu.com/;}}}

访问localhost:80 

跳转到百度

负载均衡

负载均衡是一种常见的网络技术,用于将流量在多个服务器之间平均分配,以提高系统的性能、可伸缩性和可靠性。负载均衡器(Load Balancer)作为中间层,接收来自客户端的请求,并将请求转发到后端的多个服务器上进行处理。


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;# gzip on;upstream httpd {server 192.168.2.1:81 weight=10 down;server 192.168.2.3:80 weight=1;server 192.168.2.4:80 weight=1 backup;}server {listen 80;server_name localhost;#默认编码charset utf-8;# access_log logs/host.access.log  main;location / {#反向代理的urlproxy_pass http://httpd;}}server {listen 81;server_name localhost;#默认编码charset utf-8;# access_log logs/host.access.log  main;location / {root   html;#定义首页文件的名字index index.html index.htm;}}}
  1. down:表示当前的server暂时不参与负载
  2. weight:默认为1.weight越大,负载的权重就越大。
  3. backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。

动静分离 

动静分离方面有着广泛应用。使用Nginx进行动静分离可以提高网站的性能和可伸缩性,并减轻后端服务器的压力。


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;# gzip on;upstream httpd {server 192.168.2.1:81 weight=10 down;server 192.168.2.3:80 weight=1;server 192.168.2.4:80 weight=1 backup;}server {listen 80;server_name localhost;#默认编码charset utf-8;# access_log logs/host.access.log  main;location / {#反向代理的urlproxy_pass http://httpd;}# 静态资源location /css {root /usr/local/nginx/static;index index.html index.htm;}location /images {root /usr/local/nginx/static;index index.html index.htm;}location /js {root /usr/local/nginx/static;index index.html index.htm;}	}server {listen 81;server_name localhost;#默认编码charset utf-8;# access_log logs/host.access.log  main;location / {root   html;#定义首页文件的名字index index.html index.htm;}}}

http://www.lryc.cn/news/175549.html

相关文章:

  • LLM-TAP随笔——大语言模型基础【深度学习】【PyTorch】【LLM】
  • 蓝桥杯备赛-上学迟到
  • 基于 MATLAB 的电力系统动态分析研究【IEEE9、IEEE68系节点】
  • 2023百度之星 题目详解 公园+糖果促销
  • C++ 2019-2022 CSP_J 复赛试题横向维度分析(中)
  • 基于Spring Boot的IT技术交流和分享平台的设计与实现
  • 智算引领·创新未来 | 2023紫光展锐泛物联网终端生态论坛成功举办
  • 网络安全技术指南 103.91.209.X
  • 用flex实现grid布局
  • 东郊到家app小程序公众号软件开发预约同城服务系统成品源码部署
  • kotlin的集合使用maxBy函数报NoSuchElementException
  • Python开发与应用实验2 | Python基础语法应用
  • 网络安全--防火墙旁挂部署方式和高可靠性技术
  • c++最小步数模型(魔板)
  • 【每日一题Day337】LC460LFU 缓存 | 双链表+哈希表
  • 解决老版本Oracle VirtualBox 此应用无法在此设备上运行问题
  • 法规标准-UN R48标准解读
  • 自动化和数字化在 ERP 系统中意味着什么?
  • python nvidia 显卡信息 格式数据
  • LeetCode每日一题:1993. 树上的操作(2023.9.23 C++)
  • 绿色计算产业发展白皮书:2022年OceanBase助力蚂蚁集团减排4392tCO2e
  • 阿里云通义千问14B模型开源!性能超越Llama2等同等尺寸模型
  • 两横一纵 | 寅家科技发布10年新征程战略
  • 二值贝叶斯滤波计算4d毫米波聚类目标动静属性
  • 【刷题笔记9.25】LeetCode:相交链表
  • 打造本地紧密链接的开源社区——KCC@长沙开源读书会openKylin爱好者沙龙圆满举办...
  • Python 笔记03(多线程)
  • mysql-4:SQL的解析顺序
  • 如何通过优化Read-Retry机制降低SSD读延迟?
  • matlab自动生成FPGA rom源码