skip to content

Environment Settings & Health

The generated production.rb sets far-future asset headers and silences health-check logs, and the /up route hits Rails::HealthController. Interviewers ask what /up proves and how envs differ.

part ofRuby on Railsread it →
on this pageshow

explore

questions

5

In a Rails 8.1 app, what does the generated `/up` route do, and what does a 200 from `Rails::HealthController` actually prove to a load balancer?

level: juniorimportance: must knowfreq 52%

answer

  1. rails/health#show, as: :rails_health_check
  2. inherits ActionController::Base, skips ApplicationController
  3. green page, or JSON status up
  4. rescue_from(Exception) renders 500
  5. no database, cache or queue check

basics

~20 s

/up routes to Rails::HealthController#show, which answers 200 with a green page, or JSON status: "up", once the app has booted and can serve a request. It does not check the database, cache or job queue.

solid answer

~40 s

The generated `config/routes.rb` has `get "up" => "rails/health#show", as: :rails_health_check`. `Rails::HealthController` inherits from `ActionController::Base`, not your `ApplicationController`, so authentication `before_action`s and `allow_browser` never block it. `show` renders a page with a green background, or in Rails 8.1 `{ status: "up", timestamp: ... }` for `/up.json`; a `rescue_from(Exception)` turns an error inside the action into a red page or `status: "down"` with 500. A 200 therefore proves the process booted, Puma accepted the request and it passed the middleware stack and the router. It proves nothing about PostgreSQL, Solid Queue or an external API. The generated `production.rb` also sets `config.silence_healthcheck_path = "/up"`, so frequent probes do not flood the logs.

code

bash · 5 lines
bash
curl -s https://staging.quotes.example/up.json
# {"status":"up","timestamp":"2026-10-06T09:15:02Z"}

curl -s -o /dev/null -w "%{http_code}\n" https://staging.quotes.example/up
# 200

go deeper

for a junior

Know the route, the controller it hits, and that a 200 means the app booted and can serve a request, nothing more.

for a middle

Explain why it bypasses ApplicationController, the HTML and JSON responses, the 500 path, and how silence_healthcheck_path matches paths exactly.

for a senior

Design the probe setup: which path the balancer polls, what stops it reaching the controller, and when a separate deep check is worth its restart risk.

for a principal

Set a team standard for shallow versus deep health signals and which ones are allowed to remove instances from rotation automatically.

## The route and the controller A Rails 8.1 app is generated with a health-check route in `config/routes.rb`: ```ruby get "up" => "rails/health#show", as: :rails_health_check ``` It dispatches to **`Rails::HealthController#show`**, a controller that ships inside railties. Three details in its source matter: - It inherits from **`ActionController::Base`**, not from `ApplicationController`. Callbacks you add there, such as the authentication generator's `require_authentication` or the generated `allow_browser versions: :modern`, never run for `/up`. - `show` calls `render_up`, which uses `respond_to`: HTML gets a minimal page with a green background; since **Rails 8.1.0** JSON gets `{ "status": "up", "timestamp": "<ISO 8601>" }`. - `rescue_from(Exception) { render_down }` turns any exception raised while handling the request into a red page, or `{ "status": "down", ... }`, with status **500**. ## What a 200 proves, and what it does not | A 200 from `/up` shows | A 200 from `/up` does not show | |---|---| | The app finished booting; a boot error means Puma never serves | The database is reachable | | Puma accepted the connection and had a free thread | Solid Queue workers are running | | The request passed the middleware stack and the router | Solid Cache or an external quote API responds | | A controller action rendered successfully | Pages that touch models or views render | The controller's own comment says it "does not reflect the status of all of your application's dependencies" and warns that checking third parties can get a healthy app restarted because something else is down. That is why the default is shallow. ## Keeping probes quiet and reachable A load balancer that polls every few seconds would fill the log. The generated `production.rb` sets: ```ruby config.silence_healthcheck_path = "/up" ``` That inserts `Rails::Rack::SilenceRequest` just before `Rails::Rack::Logger`. It compares the path with `===`, which for a String is plain equality, and wraps matching requests in `Rails.logger.silence`, raising the log level to error for that request only. Consequences: 1. `GET /up` and `HEAD /up` are silenced. 2. `GET /up.json` is **not**, because the string differs; set the option to the path your balancer actually polls. 3. Errors inside the request are still logged, since `silence` only hides messages below error. Two other production settings can stop a probe from reaching the controller, which is why the generated file carries commented examples next to them: enabling `config.hosts` (the probe's `Host` may be an internal IP) and turning on `force_ssl` (a plain-HTTP probe would get a redirect). Their configuration belongs with the security-header settings. ## Traps interviewers look for - **"It checks the database."** It does not; the action renders without touching a model or a connection. - **"Authentication will lock the balancer out."** It cannot, because the controller skips `ApplicationController` entirely. - **"A 500 means the app did not boot."** An app that failed to boot never answers at all; a 500 from `/up` means the request reached the controller and something raised while handling it. - **"Renaming the route breaks silencing."** It does, unless you change `silence_healthcheck_path` to the new path as well. ## Using it for the pet-insurance staging balancer For the quote app's staging environment behind a load balancer: - point the balancer's health check at `/up` (or `/up.json` if it parses bodies, and set `silence_healthcheck_path` to match); - expect HTML by default, so a check that only looks at the status code works with either format; - use it as the "can this instance serve?" signal, not as a dependency monitor; - if you need a deeper check, route a path such as `get "healthz" => "rails/health#show"` for the shallow one and add your own controller for the deep one, rather than editing the built-in. ## Renaming or replacing it The path is just a route. You can move it (`get "healthz" => "rails/health#show", as: :rails_health_check`) or point it at your own controller. If you write your own, keep it fast, skip authentication explicitly, and decide deliberately which failures should take an instance out of rotation.

  • The quote app's balancer polls `/up.json`, yet every probe still appears in the production log. Why?
    `Rails::Rack::SilenceRequest` matches the configured path with `===`, which for a String is exact equality. `config.silence_healthcheck_path = "/up"` silences `/up` but not `/up.json`. Set the option to `"/up.json"`, or point the balancer at `/up`, which every balancer can judge by status code.
  • After running the authentication generator, does `/up` start redirecting the balancer to the sign-in page?
    No. The generator includes `Authentication` into `ApplicationController`, but `Rails::HealthController` inherits from `ActionController::Base`, so `require_authentication` never runs for it. A custom health controller that inherits from `ApplicationController` would need `allow_unauthenticated_access` to stay reachable.

A 200 from /up is the receptionist picking up the phone: it proves the office is open and staffed, not that the warehouse behind it has stock or the delivery van starts.

  • A 200 from /up means the database and job queue are healthy
  • /up goes through ApplicationController, so its before_actions apply
  • config.silence_healthcheck_path also silences /up.json
  • /up only answers JSON in Rails 8.1
  • Edit Rails::HealthController itself to add dependency checks

Assumes Rails 8.1; the JSON response for /up.json was added in Rails 8.1.0, so earlier apps answer HTML only.

open as a page

In a Rails 8.1 app's production.rb, what do `config.public_file_server.headers` and `config.asset_host` each control once a CDN fronts the pet-insurance quote site?

level: middleimportance: should knowfreq 34%

basics

~20 s

public_file_server.headers sets the response headers on every file Rails serves from public/, generated as a one-year public Cache-Control. asset_host makes asset helpers emit URLs on another host, such as a CDN that pulls those files from the app.

open as a page

How does Rails 8.1 decide `Rails.env` from `RAILS_ENV` and `RACK_ENV`, and what do `Rails.env.production?` and `Rails.env.local?` return on a staging deploy?

level: middleimportance: should knowfreq 36%

basics

~10 s

Rails.env takes RAILS_ENV, falls back to RACK_ENV, then to "development", ignoring empty values. With RAILS_ENV=staging, Rails.env.staging? is true while production? and local? are false; local? is true only for development and test.

open as a page

Why does adding `config.x.quote_api_url = ENV.fetch("QUOTE_API_URL")` to a Rails 8.1 production.rb break the generated Docker build, and how should environment files read ENV?

level: seniorimportance: should knowfreq 32%

basics

~20 s

production.rb runs whenever the app boots in production, including the build stage's assets:precompile, where QUOTE_API_URL is not set, so ENV.fetch raises KeyError and the build fails. Give optional values defaults and read required ones where they are used.

open as a page

In Rails 8.1, what changes when the pet-insurance quote app's staging runs RAILS_ENV=staging with its own environment file instead of RAILS_ENV=production with staging ENV values?

level: seniorimportance: should knowfreq 30%

basics

~20 s

RAILS_ENV=staging needs its own staging.rb, a database.yml entry and staging credentials, and skips production?-only code and :production gems. RAILS_ENV=production with staging ENV values runs the exact production code path and differs only in configuration values.

open as a page