Welcome! Log In Create A New Profile

Advanced

Trying to use nginx + passenger for a rails 6 + angular 14 app...

Patrick J. Collins
February 15, 2024 03:50PM
I have a rails app that is purely an api server, with an angular frontend living under a subfolder in the public directory.. So the server's file structure is like this:

```
home/
my-app/
app/
controllers/
..etc
config/
..etc
public
favicon.ico
404.html
angular-app/
index.html
12345.js
45678.js
some-picture.jpg
```

I had a wildcard route in my rails app that was manually loading the angular files and serving them, and I am trying to let nginx server them as static files and no longer do this. The desired behavior that I am looking for is:

* visiting '/api/*' will render the response from the rails server
* visiting '/' will render the index file inside `public/angular-app/index.html`
* visiting '/404.html' will render `public/404.html`
* visiting '/some-picture.jpg' will render `public/angular-app/some-picture.jpg`

it seems that passenger is breaking the behavior that I want... If I have just a vanilla nginx config that has:

```
server {
...
root '/home/my-app/public'

location = / {
index angular-app/index.html;
}

location {
try_files $uri angular-app/$uri;
}
...
}
```

Then the behavior for visiting `/`, `/404.html`, and `/some-picture.jpg` is all perfect... But to get the rails server stuff to work, I need passenger... and as I add to the config:
```
passenger_app_root /home/my-app/;
passenger_enabled on;
```

Then trying to go to anything other than an api route (routes defined in the rails app's config) will result in a 500...

I tried experimenting with restructuring my nginx config to something like:
```
server {
...
root '/home/my-app/public'

location /api/ {
passenger_app_root /home/my-app/;
passenger_enabled on;
}

location ^/api/ {
index angular-app/index.html;
passenger_enabled off;
}
...
}
```
And I still end up with 500s going anywhere other than api endpoints... Does
anyone one know what I can do to make this work?

Patrick J. Collins
https://collinatorstudios.com
_______________________________________________
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Trying to use nginx + passenger for a rails 6 + angular 14 app...

Patrick J. Collins February 15, 2024 03:50PM

Re: Trying to use nginx + passenger for a rails 6 + angular 14 app...

Patrick J. Collins February 16, 2024 11:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 133
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready