nginx

Linux_339_Nginx七层转发实战

2022-12-20  本文已影响0人  为宇绸缪

Nginx七层转发实战

检测移动端客户端
1.修改nginx.conf支持移动端检测,修改部分代码如下
针对移动端系统的不同,进行转发动作

location / {

if ($http_user_agent ~* "android")
{
return "501";
}

if ($http_user_agent ~* "iphone")
{
return "502";
}

proxy_pass http://default_pools;
include proxy.conf;

}

重启
nginx -s reload

直接通过curl命令,模拟客户端发起HTTP请求
curl -A "android" www.chaoge.com

通过文件扩展名转发

【方法一:通过location匹配】
1.通过检测用户发请求的文件后缀名来转发

location ~ .*.(gif|jpgjpeg|png|bmp|swf|css|js)$ {
        # proxy_pass http://static_pools;
        # include proxy.conf;
        return 503;
}

# 重启nginx -s reload

【方法二:通过shell语句判断】

if ($request_uri ~* ".*\.(php|php5)$")
{
    proxy_pass http://php_server_pols;
}

if ($request_uri ~* ".*\.(jsp|jsp*|do|do*)$")
{
    proxy_pass http://java_server_pools;
}
if ($request_uri ~* ".*\.(jpeg|jpg|gif|png)$")
{
    proxy_pass http://java_server_pools;
}
上一篇下一篇

猜你喜欢

热点阅读