Home  >  Q&A  >  body text

How nginx matches different static resource directories based on paths

How nginx matches different static resource directories based on paths

location /console/ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
    root /opt/jenkins/workspace/little_garden_web/console;
    index /opt/jenkins/workspace/little_garden_web/console/index.html;
    expires      30d;
}

location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
    root /opt/jenkins/workspace/little_garden_web/dist;
    expires      30d;
}

I hope that when the path contains console, a special static resource directory is accessed, and everything else is obtained from another one. I don’t know how to write the configuration file

给我你的怀抱给我你的怀抱2712 days ago699

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-16 17:09:51

    You can take a closer look at some configurations of nginx regarding location and provide a method

    location ^~ /console/ {
        root /console;
        expires  30d;
    }
    
    location ~* \.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
        root /dist;
        expires  30d;
    }

    reply
    0
  • Cancelreply