nginx功能:
(1)web服务器:
默认网页目录为:/usr/share/nginx/html
(2)反向代理服务器:
nginx代替客户端访问后端服务器,后端服务器只知道是nginx的请求,并将结果返回给 nginx,nginx 在返回给客户端结果
找到nginx配置文件中 location,配置段如下,默认是空的参数
location / {
}
做反向代理,/ 后面加上虚拟路径名字,下面用 proxy_pass 模块和上游的服务器的url,例如:
location /node1 { proxy_pass http://192.168.210.131/; }
(3)负载均衡服务器:
nginx 负责转发客户端的请求,轮询到的后端服务器获得的是客户端的访问请求,服务器直接返回给客户端结果 先配置 location 中的反向代理,将客户端请求发送到一个集群(zn为集群名,可以随便起),然后用 upstream 模块声明集群,并写入后端的真实server的地址,例如:
include /etc/nginx/conf.d/*.conf; upstream zn { server 192.168.210.132 weight=2 max_fails=2 fail_timeout=2; server 192.168.210.131 weight=1 max_fails=2 fail_timeout=2; } server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; index index.php index.html; # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; location / { proxy_pass http://zn/; }
原文:https://www.cnblogs.com/cloudhere/p/10946522.html