Hosting a rails app inside another website's directory - ruby-on-rails

I have a php site on my server, suppose it is example.com.
And I want to run an rails app inside the domain like example.com/rails.
I am using nginx and tried to edit the example.com's host config and proxied the /rails location to unicorn upstream. But that did not work.
Is it possible to do like example.com/rails ?

Related

Same domain hosting of both static landing page and Rails app on sub-uri with Dokku

I currently have the following scenario on one of my VPSs:
https://example.com - Landing page hosted on root of domain
https://example.com/app - Nginx proxying /app to my Rails app on same VPS (served by Puma)
Need to migrate both to a new server as Dokku apps and that should result in two apps: one for the static landing page and one to the Rails app. Is that even possible? If yes, any tips?
Thanks!
Got it working by setting a reverse proxy on the landing page app's nginx config file, pointing to the main app:
Disable VHOST support on main app, since it won't be reachable outside or by a domain name. This will create a local listening container on a high numbered port
Add a proxy.conf file to /home/dokku/landing-page/nginx.conf.d/
Set up a reverse proxy on a 'location /app/' block inside that file. Set the upstream to the main app's IP and PORT (from the first item).
That's the main steps. Had to tweak forwarded headers a bit to get SSL working fine, but it works fine!

Let Rails trigger update of nginx config?

I'm currently adding user domains to my Rails application. Which means they can use example.com to reach their profile page on my Rails app. I've already implemented this on the Rails side but what's missing is the Nginx side.
How can the Rails app somehow update the Nginx config (add/remove specific domain) and let Nginx reload the config to handle requests from these domains?

How to deploy an ember-cli app that interacts with a rails API backend to a VPS

I have completed development of an ember.js app for the time being, and am wondering how I can deploy it to a production server? I successfully built a dist dir within the app, and I also cloned the ember app repo to the production server.
I am deploying the rails app with capistrano from my local box to the VPS, and everything appears to be working there. Side note, I am using Nginx as the web server, and puma as the application server for the rails apps.
Also, I have the local dev versions of the ember / rails app working great on my local box running the below commands,
rails s --binding 127.0.0.1 and,
ember server --proxy http://127.0.0.1:3000
So I decided to copy the files that were in the dist dir to the public dir of the rails app, and move the assets for the ember app to the assets dir of the rails app.
On my local dev box, I see CSV files being presented like,
However when I load the "ember app" on the production box I am not seeing the CSV files being presented like,
Which brings me to my question, what is the proper way to deploy a ember-cli app to a production server and have it communicate to a rails API backend?
UPDATE
This is what I am seeing in the network tab,
In an ideal system, I use this setup:
On disk:
/srv/frontend/
/srv/backend/
frontend
With Ember CLI, /srv/frontend contains the output of ember build. I can use the --output-path=/srv/frontend flag to set this, if the Ember CLI source is also on the same machine. All API requests should be prefixed with /api. I do this by setting the namespace property to my ApplicationAdapter to api/ (or api/v1 sometimes.)
backend
/srv/backend contains my backend API (The location doesn't really matter in most cases).
For the Rails API, I use puma as a standalone server. As long as you have a standalone server that listens on a port, it doesn't matter if it's puma or something else. All API routes must be namespaced under /api. you can wrap all your routes in a scope block to do this without changing your codebase. I go one step further and add another namespace v1.
reverse proxy
Then I install nginx and make my config like this:
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
# add SSL paths
server_name localhost;
# UI, Static Build
location / {
alias /srv/frontend/;
index index.html;
}
# Rails API
location /api {
proxy_pass http://localhost:3000/;
}
}
So now I have an Nginx config that proxies / requests to the /srv/frontend/index.html and /api requests to Puma on port 3000.
The only downside to this is that I'm forced to use hash location on my Ember application. There are ways to circumvent this, but it's just easier to use hash location and history location doesn't really buy me much.

Adding Subdomain for my ruby on rails server, how to do?

i've got some problems with my ruby on rails server.
It is running under localhost:3333 in my debian vm under a windows8 host.
I've installed apache2 and passengermodul for apache to get ruby. And then I've installed rails.
Now I need a subdomain wich calls the ruby on rails server.
for example admin.localhost:3333
Is something like that possible? And when how can I configurate it?
You can use the lvh.me domain. That domain has a DNS entry that will redirect to localhost. This also works for subdomains, so you can visit admin.lvh.me:3000 and it will redirect to localhost:3000 while still having the subdomain available in the Rails request.
The advantage is that you don't have to edit your localhost file.
Add custom hosts with subdomains to the hosts file, follow these steps
In your terminal, open hosts file
cd /etc
sudo nano hosts
Add the host as mentioned in the following lines to the hosts file, you can add as many as you want
127.0.0.1 admin.localhost
127.0.0.1 subdomain.localhost
Save the file, CTRL + X then press Y
Done.
To run with a custom port, specify the port number while starting the server,
rails s -p 3333
Now you can run your application with, admin.localhost:3333
Hope this helps!

Nginx hosting a single Rails app on sub uri

Background:
I am running a debian 7 server behind a reverse proxy.
I have a rails 4 app running ruby 2.0.0-p247
I am using nginx
Server is accessed by navigating to: server-name.foo.dev where foo.dev is the internal reverse proxy domain.
I am unable to use passenger to deploy the app.
This will be the only app running on the server.
Problem:
I need to host the rails app on a sub uri or context root path on the server behind the reverse proxy, so that when users navigate to the website, the url for the root path looks like this:
server-name.foo.dev/rails_app, where rails_app would be the root of the rails app.
How would I set this up in nginx sites-enabled config file, and is there anything I would have to modify on the rails app to allow it to sever the correct paths to static content.
I strongly recommend to use Unicorn instead of Passenger.
You can set up both of them(Unicorn and Nginx) as reverse proxy.
This link will be pretty good paper for you..
Again, you 'rewrite'(Nginx route feature) /rails_app to rails application's Unicorn socket file(usually using upstream).
See also below code snippets.
partial nginx.conf
location ~* ^/(rails_app)/ {
root /your/rails/home;
index index.html index.htm;
proxy_pass http://socket_proxy_name;
}
partial snippet for proxy_pass
upstream socket_proxy_name{
server unix:/your/socket/paht.sock fail_timeout=0;
}

Resources