How to setup wordpress site and rails multiaccount site - ruby-on-rails

I have TLD (www.example.com) and want to deploy rails 3 app (ex. app.example.com) what will have multiple accounts, each account with one subdomiain (test.example.com, support.example.com, ...).
I created tld with subdomain, changed DNS records, and everything is working. But, since there will be CNAME redirection from some other sites to specific subdomains and my default site is TLD (www.example.com) all CNAME redirects are going to main site instead of analogus subdomain!
Is there better way to integrate Rails and Wordpress? How to solve that? I'm searching for solution last two days.
Similar question: https://stackoverflow.com/questions/10405859/how-to-config-apache-passenger-for-wordpress-and-rails

If your ruby is in passenger mode, and your apache servicing all http queries you should be able to use the apache virtual server setup to redirect the queries for your rails apps accordingly, while leaving your Wordpress on the default web server.
I haven't done it with rails, but for Diaspora, (which is a ruby app) I have that running side by side with a Wordpress network with numerous subdomains off the TLD. The key might be that your TLD should be example.com, not www.example.com. (setup whichever you prefer to have wordoress on to redirect to the other)
Post some more details on your apache (or other web server environment) setup to achieve some better assistance if this doesn't help.
Yours for the cause of open source!

Related

How to do multi-tenant support with custom domains and SSL on Heroku

My app allows users to create custom product landing pages.
I wish to setup this scenario:
Pages can exist on brand.myapp.com/offer-name, however I want to enable users to create landing pages using their own domain, for example brand.customerdomain.com/offer-name, which serves a page from my app.
I am unsure about the best way to do this. I know I can have users point a CNAME record to 'myapp.com', and then I add 'brand.customerdomain.com' as a Heroku custom domain. But is there a limit to the amount of custom domains I can add to Heroku? There will be thousands of these domains, so I don't know if this solution is feasible. I have had some success with this approach, however I get SSL browser messages when accessing the page from the user's domain.
In terms of SSL, I have a wildcard certificate installed on Heroku, for *.myapp.com.
Another way is to have a proxy server hosted elsewhere, and have users point a CNAME to something like 'proxy.myapp.com', which routes to my Heroku URL, however I haven't been able to get this to work on Nginx (on DigitalOcean), and haven't found any suitable guides (I don't have much Nginx knowledge).
The proxy approach I found here - https://mrvautin.com/enabling-custom-domain-for-saas-application-on-heroku/.
Cloudflare has a solution for this problem, however it's available to enterprise customers only, so I'd prefer to have my own solution - https://www.cloudflare.com/saas/.
What would be the ideal way to have multi-tenancy, with custom domains and SSL on Heroku?

is it possible to have multiple project of rails on same port?

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.

How do I create 301 redirect from WordPress (hosted on wsynth) to a Rails app hosted on Heroku?

I have a website (example.com) that is a WordPress site hosted on WSYNTH.
I am redesigning the site, same domain (example.com) in ROR hosted on Heroku.
I have been told that for SEO purposes, once I point my domain to the ROR app on Heroku, all the old pages from the Wordpress site will go dark. (Makes sense.) But this would be very bad for SEO, since example.com will now have many URLs associated with it (created from the WP site) that are no longer valid.
I've heard that a 301 Redirect for those WordPress URLs will take care of this SEO issue. But how and where should I do this? Should I be installing a plugin in WordPress that will automate the redirects to the pages I want to send them to in the ROR/Heroku app?)
Also, is it possible to keep some of those old WordPress URLs live?
DNS
The 301 redirect is not the issue - you can use Wordpress itself to redirect to specific pages (using the simple 301 redirects plugin), or a better way will be to redirect your domain (with your DNS) to your Rails app, and then use the routes to handle any stray pages
The world of "SEO" is highly overrated - Google is just a system which
follows links. If it cannot find a page, it removes it from its
rankings; if it can find the page, it judges its on & off-site
optimization to determine its relevance.
This means the only thing you need to concern yourself with is ensuring you don't have any "holes" in your URLs. The redirections essentially mean you will tell Google to follow a link to the new page
--
Redirections
The first thing you need to do is ensure you have the new pages you wish to show on your site. Preferrably, you'll want to make as many of them as identical to your previous URLS as you can.
Secondly, you can introduce redirects in your Rails routing system to give Google real pages when it visits the links for your Wordpress site:
#config/routes.rb
get '/your-old-post-name', to: redirect('/your-new-post-name')
This will mean you will have to create redirections for every wordpress post in your new Rails app - but should give Google the knowledge that those pages have changed, to which it will update

Set up custom domains for users using rails 4, nginx with passenger

I have a rails application that uses subdomains to allow users to have their own seperate data in a CMS system. Basically a SaaS CMS system like wordpress.com or tumblr.com.
However i would like to give users the ability to choose their own domain (av alias for their subdomain). For example the user henrik.cmsdomain.com would like to have a custom domain that reads henrikswebsite.com.
How can i do this? Do i need to set up my own name servers? I'm not necessarily looking for complete answers, i just don't know where to start.
Im running on an ubuntu 13.10 digitalocean server with nginx, passenger, Rails 4 and postgresql (using schemas to seperate userdata).
What you're looking for is something called "virtual subdomains" (I think). Here is some information about how to set them up:
http://signalvnoise.com/posts/1512-how-to-do-basecamp-style-subdomains-in-rails
Rails Restful Routing and Subdomains
You basically need to set up a "wildcard" subdomain in your DNS (which will route all subdomain requests to your app), and let the routing middleware handle the request (& route accordingly)
Domains
Considering the updates, I have had a look online for you:
Rails routing to handle multiple domains on single application
I don't have experience of this directly, but I'd say you first need to get the domain to point to your site (with CNAME changes). This could then be caught by your routing middleware (as described in the link above), allowing you to "route" the request accordingly
Heroku does this exact thing - it's quite common

Configuring multiple applications in RoR

I would like to have multiple RoR applications that can communicate with each other (databases, method calls, ...).
Example of what I would like:
a main application running on a URL http:// www.< application_name >.com
a sub-application 1 running on a URL http:// www.< application1_name >.< application_name >.com
a sub-application 2 running on a URL http:// www.< application2_name >.< application_name >.com
each with own databases.
How can I configure my applications? Where can I find a tutorial for my needs?
No Problem. In your case you will have 3 distinct Rails applications. You will setup your Webserver to send requests based on host accessed to one of the three applications. This is standard web server configuration. You'll need to read Apache or Nginx configuration on how to route request to the right rails application.
EDIT:
http://articles.slicehost.com/2009/3/11/ubuntu-intrepid-nginx-rails-and-mongrels
Not sure what you are going to use as your Web Server (Apache or Nginx or something else) or what you are going use as your application container (mongrel/passenger/thin etc) but this article above should help.
You might take a look at the eco_apps gem - https://github.com/idapted/eco_apps. I heard the developers give a talk about it at Rails Conf '10. Fascinating stuff, though I haven't had a chance to use it yet.

Resources