Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!