Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

617
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda