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

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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