nginx反向代理及负载均衡
扩展:OpenResty:有很多第三方的插件,下载地址:http://openresty.org/cn/download.html
// 修改 nginx配置文件 nginx.conf
// echoc插件可以直接输出文字
location /{
echo 'hello nginx' // echo插件:可以直接输出中文
}
// 配置完成之后刷新页面会下载文件
// 在location的上面添加
default_type text/html;
location /{
echo 'hello nginx'
}
location匹配方式
最高:匹配='/a'的:localhost:8080/a
location = /a {
echo '/a'
}
第二:匹配以什么什么开头的
location ^~ /a {
echo '^~ /a'
}
第三:正则表达式
location ~ ^/\w {
echo '~ ^/\w'
}
最弱:以‘/’开头的所有请求 ,lcoalhost:8080/xxx/xx/xx/xx
location / {
echo 'hello nginx'
}
同级比较,以上面写的为准
nginx 反向代理
server {
listen 80;
server_name localhost;
default_type text/html;
// 表示访问‘http://localhost:8080/’会访问到‘http://192.168.0.12:80’这个上面
location /{
proxy_pass http://192.168.0.12:80;
}
// 表示访问‘http://localhost:8080/a’会访问到‘http://192.168.0.12:80/a’这个上面
localtion /a{
proxy_pass http://192.168.0.12:80;
}
// 表示访问‘http://localhost:8080/a’会访问到‘http://192.168.0.12:80’这个上面
location /a/{
proxy_pass http://192.168.0.12:80/;
}
}
nginx 负载均衡
// http里面添加
upstream group1{
server 192.168.0.12:80 weight=10;// 权重
server 192.168.0.12:81 weight=1;
}
location /a/ {
proxy_pass http://group1/;
}

浙公网安备 33010602011771号