1.Nginx配置负载均衡
upstream cluster1{ //1.配置机器集群,并配置权重
server 192.168.3.3:8090 weight=8;
server 192.168.3.4:8099 weight=3;
server 192.168.3.5:8099 weight=2 down;//down表示不使用
server 192.168.3.6:8099 weight=1 backup;//backup表示备用
}
upstream cluster2{ //1.配置机器集群
server 192.168.3.3:8090;
server 192.168.3.4:8099;
}
server {
listen 80;
server_name icmsautopotal;
client_max_body_size 4096M;
location = / {
proxy_pass http://cluster1;//2.配置代理
#root /usr/share/nginx/html;
#index index.html;
#add_header Cache-Control "no-cache, no-store";
}
2.Nginx配置动静分离
location /home {
root /www; #等价于/home/www/,拼接/home
expires 7d;
}
location /static1 {
alias /home/www/; #别名
expires 7d;
}
location /static/ {
root /usr/share/nginx/html;
expires 7d;
}
3.开启gzip
4.location 表达式
1)不带符号,前缀匹配:
location /static {
alias /etc/nginx/www; #alias别名指定绝对路径
}
表示访问192.168.2.201/static/*下的所有静态资源,去找/etc/nginx/www下对应的资源
比如:192.168.2.201/static/1.jpg 去找/etc/nginx/www/1.jpg
2) "="符号,绝对匹配
"=" :用于不包含正则表达式的uri前,必须与指定的模式精确匹配
location = /abc/ {
root /etc/nginx/html/;
index index2.html;
}
只有192.168.2.201/abc/能返回/etc/nginx/html/index2.html,其余的都无法返回
3)"~":用于表示当前uri中包含了正则表达式,并且区分大小写 ;
"~*": 用于表示当前uri中包含了正则表达式,并且不区分大小写;前提是目录中有1.JPEG图片
location ~* \.(jpg|jpeg) {
root /usr/local/nginx/html/img/;
}
匹配.jpeg后缀的图片到/usr/local/nginx/html/img/
5.Nginx配置跨越
6.Nginx配置防盗链
7.Keepalive配置长链接
8.反向代理缓存设置
9.Nginx配置化Https