I have two Rails apps that I want to serve with Passenger from the same domain.
I would like requests to come in to one app, and if that app is not able to handle the request, for the request to be passed to the the second app.
I know that I can use Passenger's RailsBaseURI option to deploy multiple apps to different sub URIs, but this doesn't give the behaviour I'm after.
Is there a standard way to achieve this?
Thanks in advance, etc etc.
I think you can use haproxy as a load balancer.
Related
I want to add a new project beside of my current rails app without starting a new server for that.
I think it is impossible to have two rails app on one port but my boss want it.
Is it possible at all?
Yes it's possible if you configure a web server (nginx, etc) as a reverse proxy to listen on the port you want, and have it forward traffic to the correct app based on subdomain.
Yes and no. You can't run two web servers, e.g. Puma, on the same port. That won't work. But you can run one web server to serve two Rails apps. Incoming requests are routed based on either their subdomain (app1.example.com) or their path (example.com/app1).
A common setup is to use Apache/nginx as the web server in combination with Passenger as the application server. This question ask a similar question and points to Passenger's documentation on how to serve apps from subdomains: How to deploy multiple rails app on a single IP (Apache + Passenger)?
The configuration depends heavily on your setup, so I can't give you a more detailed answer. But searching for "multiple apps" and the combination of your web and application server should yield enough results and tutorials for you to solve your problem.
I'm looking for the way to serve multiple rails apps on one server. I uploaded one of the apps and it works just fine. But as soon as I create nginx configuration for a new app, it crashes first one.
I can't find an appropriate guide for this. If you have any advice, please share.
it can surely help you with reverse proxy as well as serving multiple apps:
https://gist.github.com/soheilhy/8b94347ff8336d971ad0
I'm developing a web application with an AngularJS frontend and a Rails backend.
My goal is to keep the two entirely separate, since the Rails app will ultimately be relegated to a simple REST server, and the AngularJS frontend will be just one of a few different clients that use the backend. For that reason, I don't want to integrate the frontend into the Rails asset pipeline, or similar.
The Rails app is running locally on port 3000. The frontend uses Gulp to compile static assets, and BrowserSync, which contains a development server that I'm running on port 3001.
For development purposes, how can I get the AngularJS app to talk to the Rails server, avoiding this browser error (which I'd expected) when making HTTP request via Angular's $http service?
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3001' is therefore not allowed access.
Do I just need to set up CORS in the Rails app? Is there another way - maybe some sort of local hosts file trick (I'm on a Mac, FWIW) or similar? I ask because my coworker is responsible for the Rails app (I have limited experience with Rails) but is out of town for a while; my knowledge is mostly limited to the AngularJS stack that I've set up.
I've searched and read up for about an hour, but haven't yet been able to find anything that I can grok that is applicable to my situation. I might not be aware of the best search terms.
Thanks for any help!
Ah, wonderful. Here are a few solutions:
set up CORS, which shouldn't be too hard. All you have to do is add the headers to pages serving your static content (not the rails REST endpoints), The problem with this is you shouldn't really be doing it unless you have a good reason (so see 3). How are you serving the static content? There should be plugins to do the headers for you if it's a popular tool
serve the angularJS pages from the rails backend for now (using some kind of static route)
if you're thinking about production and want to sort this out for good, use nginx to proxy the two services into one single domain, http://nginx.org/en/docs/beginners_guide.html
I have different websites/applications built with rails, which has different domain names. The thing is I want to serve them from a server with Nginx/passenger. I tried some techniques, but I cannot make them work, basically, I have very few information about this.
So, I can serve different websites/applications on different ports. But how can I make people to see application "AAA" if they are coming from aaa.com and see application "BBB" if they are coming from bbb.com?
Phusion Passenger's documentation has a passage on this here, section 3.2: http://www.modrails.com/documentation/Users%20guide%20Nginx.html
Basically, you can set up virtual hosts that point to different applications on the same web server/app server pair.
You can also do rewrites or forwarding purely through nginx configuration, if the above doesn't work.
I would like to have different applications under the same domain using Heroku.
Because of the name of the domain, I would like to access the applications using folders (mydomain.com/app) instead of using subdomains (app.mydomain.com), is this possible? Thanks
There is no type of URL re-writing you have access over thats going to do that for you. You could create a "stub" Siantra-based app that allows you to define those types of URLs, but it would have to effectively redirect you to the subdomain version.
I'd have to play devil's advocate and ask why you'd want to have things namespaced as /app instead of using subdomains. Subdomains offer much more flexibility and are a lot less brittle than essentially having to url-rewrite all the time based on the first "slash" element.
You can't do this with heroku - it assumes the directory structure of the Rails application.