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

109
Vistas
Nginx serve Rails route as default page

I'm trying to serve a specific Rails route for the default Nginx page. I have an app that allows users to create sites, but the site only becomes available under certain conditions, so until those conditions are met, the Nginx server block for that site is not created, meaning if they try to visit their site using their domain they end up seeing the Nginx default page (Welcome to Nginx).

What i'm trying to do is make Nginx serve one of the Rails routes to make it a bit more user friendly and avoid unnecessary support questions for those that don't read the instructions (which is basically all of them).

i've been trying different configs in the default Nginx config file, but to no avail, Nginx always ends up serving the root page of the Rails app instead of the specific route i want (/almost-there):

/etc/nginx/sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/railsapp/public;

    passenger_enabled on;
    rails_env production;

    index almost-there.html;

    server_name _;

    location / {
        index almost-there.html;
    }
}

Note that almost-there.html is a rails route, not an actual static html file.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I do not use this framework, but you probably need to redirect visitors to /almost-there.html but serve the /index.html as usual.

For example:

index index.html;

location = / {
    return 302 /almost-there.html;
}
location / {
    try_files $uri $uri/ /index.html; 
}

Alternatively, to redirect all routes:

index index.html;

location / {
    try_files $uri $uri/ @redirect;
}
location @redirect {
    rewrite ^/almost-there\.html$ /index.html last;
    return 302 /almost-there.html;
}
over 4 years ago · Santiago Trujillo Denunciar

0

So what I ended up doing was removing the location block entirely, as well as the index directive and instead redirecting the / to the Rails route that I wanted to display:

rewrite ^/$ /almost-there redirect;

Important to note that this is a temporary redirect instead of a permanent one as we don't want browsers to cache this redirect to avoid problems once the real site is ready to be displayed.

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