Day4 Nginx 1
uwupu 啦啦啦啦啦

Nginx

Nginx一个高性能的HTTP和反向代理的web服务器,同时也提供IMAP/POP3/SMTP服务。

作用

即:反向代理、负载均衡、动静分离。

Http代理,反向代理,

正向代理

代理客户端。
多个客户端 -> 代理 -> … -> 单个服务器

反向代理

代理服务器
多个客户端 -> … -> 代理 -> 多个服务器

image

负载均衡

轮询、加权轮询、iphash

iphash

可以解决Session不共享的问题

不建议使用Nginx用作Session共享,建议使用Redis

动静分离

动态服务请求静态服务请求分开。

conf文件

Nginx 常用命令

nginx 启动
nginx -s stop 停止
nginx -s quit 安全退出
nginx -s reload 重新加载配置文件
ps aux|grep nginx 查看nginx进程

多项目负载均衡

用Nginx均衡来自8080和8081的负载。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
http {
include mime.types;
default_type application/octet-stream;
upstream yupstream{
# 服务器资源
server 127.0.0.1:8080 weight=1; # 权重为1
server 127.0.0.1:8081 weight=1;
}


server{
listen 801;
server_name localhost;
# 代理



# 根目录请求
location / {
root html;
index index.html,index.htm;
proxy_pass http://yupstream; # 反向代理
}
location /admin {

}

}

}

 评论