Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

627
Visualizações
Serve static content through NGINX, based on subdomain name

I am trying to improve the page speed of a site I run by serving static content directly from NGINX rather than the request hitting PHP.

I have webpages at paths like this:

  • gamea.com.mysite.com
  • anotherb.net.mysite.com
  • finalc.org.mysite.com

When a page is generated for these, it's stored in a path like this:

  • /storage/app/page-cache/games/game/gamea_com/1.c
  • /storage/app/page-cache/games/anot/anotherb_net/1.c
  • /storage/app/page-cache/games/fina/finalc_org/1.c

The path structure takes the first 4 letters of the subdomain, and then follows by another folder with the full path and replaces "." with "_" - e.g. "gamea.com" = "/game/gamea_com/". The actual cache page file is stored as "1.c"

How might this be accomplished through NGINX? I'm a bit stuck, I did find this article but I'm unsure how to use it in my case - can anyone provide an example NGINX config that points NGINX to the correct path as described above?

I thank you whoever can help me with this!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The first step is to capture the three parts of the subdomain using a regular expression, then paste them into a root statement. Use named captures as the numeric captures may be out of scope where they are evaluated. See this document for details.

For example:

server {
    server_name  "~^(?<name1>.{4})(?<name2>.*)\.(?<name3>.*)\.example\.com$";
    root /path/to/root/$name1/$name1$name2_$name3;
    ...
}

Alternatively, decode the $http_host variable using a map. The regular expression is the same, and the result could be used in a root or try_files statement.

For example:

map $http_host $mypath {
    default                                                     "nonexistent";
    "~^(?<name1>.{4})(?<name2>.*)\.(?<name3>.*)\.example\.com$" $name1/$name1$name2_$name3;
}
server {
    ...
    root /path/to/root;
    location / {
        try_files $uri /$mypath$uri =404;
    }
}

You can split the try_files across two location blocks with:

root /path/to/root;
location / {
    try_files $uri @other;
}
location @other {
    try_files /$mypath$uri =404;
}

Swap the terms depending on which files you want Nginx to look for first. Use add_header statements in either location to customise the appropriate response. See this document for details. Either location can contain specific headers

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda