Deploy rails app in subdirectory
The goal is to run 2 rails app at:
Before we start, you can setup your first app like usual. I will skip the steps. If you do not understand, you can refer here for more information.
To setup your second app, follow the same steps as the usual setup. The only difference is the configuration in the server block. Instead of following the usual steps, you need to modify your Nginx server block and add these code below into it.
server {
### Other Codes
server_name www.domain.com;
passenger_enabled on;
rails_env production;
root /path/to/first_app/public;
### Add this: Handling another app
location ~ ^/another_app(/.*|$) {
alias /path/to/another_app/public$1; # Point to public folder, note the $1 behind.
passenger_base_uri /another_app;
passenger_app_root /path/to/another_app;
passenger_document_root /path/to/another_app/public;
passenger_enabled on;
}
### Other Codes
}
Add the following config in your rails app:
config.action_controller.relative_url_root = '/another_app'
Then, restart your Nginx server and that's it.
AI Summary
Chrome On-device AI
2024-11-09 06:02:26
Share Article