I want to run two Rails6 applications on the same server at two sub-URIs using NGINX and Passenger. The root is a static index.html.
The index page loads correctly from the root. So do the root views of the Rails applications when the sub-URIs are accessed. However, subsequent form submits throw 404.
Both the applications run fine when I run them on root (/) instead of the static index page.
Configuration file is sites-enabled folder has --
server {
listen 80;
server_name _;
passenger_enabled on;
passenger_ruby /usr/bin/ruby;
passenger_app_env development;
location / {
root /var/www/html;
}
location ~ ^/rbf(/.*|$) {
alias /var/www/rails6-bootstrap-flatpickr/public$1;
passenger_base_uri /rbf;
passenger_app_root /var/www/rails6-bootstrap-flatpickr;
passenger_document_root /var/www/rails6-bootstrap-flatpickr/public;
}
location ~ ^/cdb(/.*|$) {
alias /var/www/dashboard/public$1;
passenger_base_uri /cdb;
passenger_app_root /var/www/dashboard;
passenger_document_root /var/www/dashboard/public;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
The NGINX access log has the following line (I have replaced my ip address with aaa.bbb.ccc.ddd)
[19/Nov/2020:12:00:59 +0000] "POST /display_router HTTP/1.1" 404 209 "http://aaa.bbb.ccc.ddd/cdb" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
In development I had each app running on its own Rails server. The form definitions were:
<%= form_with(url: "/process_dates") do %>
and
<%= form_with(url: "/display_router") do %>
The forms were being posted to root folder /process_dates and /display_router respectively. But on the cloud server, each application is in its own folder which is the rails root.
So I just changed the form definitions on the cloud server to
<%= form_with(url: "/rbf/process_dates") do %>
and
<%= form_with(url: "/cdb/display_router") do %>
and it worked.