is it possible to specify an index.html location for a passener + nginx app?

18 Views Asked by At

I have an nginx site config like:

server {
  server_name mydomain.com;
  root /home/app/public;
  passenger_ruby /usr/bin/ruby2.7;
  passenger_app_root /home/app;
  passenger_enabled on;
  passenger_user app;
  passenger_max_request_queue_size 3360;
  passenger_max_requests 3360;
  ...
}

home/app's directory structure something like is:

(rails app)
app/
  controllers/
  ..etc
config/
  ..etc
public
  favicon.ico
  404.html
  frontend/
    index.html
    12345.js
    45678.js
    some-picture.jpg

I am trying to make it so that:

  1. visiting mydomain.com will render the index file in public/frontend
  2. any asset request will be served from public and then if it's not found, fallback to public/frontend.. For example: a request to mydomain.com/favicon.ico will serve the favicon in public, and a request to mydomain.com/some-picture.jpg will serve the jpeg in public/frontend.

...

When experimenting with a vanilla nginx config, I found that I could accomplish this by doing:

server {
  server_name mydomain.com;
  root /home/app/public;

  location = / {
    index /frontend/index.html;
  }

  location {
    try_files $uri /frontend/$uri;
  }
  ...
}

However it seems that once passenger is added to this mix, this no longer works...

0

There are 0 best solutions below