nginx动静分离,排除某个路径下的静态资源

我们的web项目在nginx上做了一次动静分离,在nginx上的配置:

location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
        root /data/vangogh/;
        expires 1d;   #使用expires缓存模块,缓存到客户端30天
    }


    ### refuse illegal access
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    ### speed limit
    #limit_req   zone=java  burst=50 nodelay;

    ### include sub config file
    #include sub.d/*.conf;

    ## web application root context for common iface2 service, featured location please specified in sub.d directory
    location / {
        proxy_pass          http://local_worker;
        proxy_redirect      off;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    Host $http_host;
        proxy_http_version  1.1;
        proxy_set_header    Connection "";

    }

有一次,我们把druid引入到系统中,配置了sql的监控页面,这时访问druid的页面会出现404,原因是nginx上配置的静态资源请求都从nginx上获取,不用转发到后端服务器。而druid的页面都是封装到jar包中的,我们无法单独获取静态资源放到nginx服务器上。所以,我们需要在nginx上多加一个配置,对于druid的请求,都转发到后端。

location ~ /druid/.*\.(html|htm|woff|ttf|svg|eot|gif|jpg|jpeg|bmp|png|ico|txt|js|css|xml)$ {
        proxy_pass          http://local_worker;
        proxy_redirect      off;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    Host $http_host;
        proxy_http_version  1.1;
        proxy_set_header    Connection "";
    }
    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
        root /data/vangogh/;
        expires 1d;   #使用expires缓存模块,缓存到客户端30天
    }


    ### refuse illegal access
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    ### speed limit
    #limit_req   zone=java  burst=50 nodelay;

    ### include sub config file
    #include sub.d/*.conf;

    ## web application root context for common iface2 service, featured location please specified in sub.d directory
    location / {
        proxy_pass          http://local_worker;
        proxy_redirect      off;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    Host $http_host;
        proxy_http_version  1.1;
        proxy_set_header    Connection "";

    }

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赶路人儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值