I have setup my Rails app on a VPS and a WordPress blog on GoDaddy. I did this because I don't want to have to install PHP on my VPS. Also, my rails app is using Postgres and while I am aware that WordPress can be setup to use Postgres, I just don't want to go through the hassle.
How do I link the blog and my rails app, such that the blog is located at:
www.mysite.com/blog
Also, when internally navigating on the blog, the base URL should remain www.mysite.com/blog
For example:
www.mysite.com/blog/article1
www.mysite.com/blog/category
And so on....
Assuming that your Rails site runs with an Apache in front, here is something you can put into the VirtualHost part of your Rails site:
<Location /blog>
ProxyPass http://godaddy.com/yourwordpress-site/
</Location>
In Nginx it would look like this
location /blog {
proxy_pass http://godaddy.com/yourwordpress-site;
}
Of course I would recommend, that you add some more options to the proxy setup so that the IP address of the original requester is kept etc. Doing it this way, the Webserver already catches the request and doesn't even bother your Rails app with requests that it doesn't really know about.
to redirect correctly, but not hide the url of the wordpress site
in your rails app's routes.rb
match "/blog" => redirect("http://YOUR_WORDPRESS_BLOG_SITE_URL")
Make sure you didn't forget to add http/https in your redirection url
Another alternative is to use a subdomain (instead of a subfolder), like blog.mysite.com, and then it can be handled using plain and simple dns.
Related
I've deployed a Rails 3.2 app to Heroku. I would like the app to be accessible from http://myapp.mydomain.com and for routes to be accessible from this url, e.g. http://myapp.mydomain.com/ModelA/1
I've followed the instructions at https://devcenter.heroku.com/articles/custom-domains
When I enter http://myapp.mydomain.com in the bowser addressbar it successfully takes me to the app.
BUT the url is rewritten as myapp.herokuapp.com
I've already added the domain to Heroku heroku domains:add myapp.mydomain.com.
How do I maintain the custom domain throughout my app?
This looks like a DNS config issue. You should check your hosting provider to make sure you have your site set up as a CNAME to proxy.heroku.com, not a redirect or anything else.
(Glad you were able to solve it!)
I'm building a rails app that I'll host on Heroku at domain.com. And I'd like to use WordPress for the blog hosted on phpfog, but I don't want to use a subdomain like blog.domain.com. I'd instead prefer to use a subdirectory like domain.com/blog
Its not about SEO...I'm just not a fan of subdomains. Subdirectories are sexier (yeah...I actually said that).
Any idea on how I can reliably accomplish this? Thanks in advance for the help.
You can use the rack-reverse-proxy gem that neezer found to do this. First you'll want to add gem "rack-reverse-proxy", :require => "rack/reverse_proxy" to your Gemfile and run bundle install. Next, you'll modify your config.ru to forward the /blog/ route to your desired blog:
require ::File.expand_path('../config/environment', __FILE__)
use Rack::ReverseProxy do
reverse_proxy /^\/blog(\/.*)$/, 'http://notch.tumblr.com$1', opts={:preserve_host => true}
end
run YourAppName::Application
You probably already have the first require statement and the run YourAppName... statement. There are a couple important details that make this work.
First, when you add your desired blog URL, you can't keep the trailing slash on it. If you do, when someone requests http://yourdomain.com/blog/, the gem will forward them to http://you.yourbloghost.com// with an extra trailing slash.
Secondly, if the :preserve_host option isn't enabled, your blog hosting server will see the request as being for http://yourdomain.com/blog/ instead of as http://you.yourbloghost.com and will return bad results.
You still may have an issue with the CSS or images if the blog uses /absolute/paths/to/images/.
I'd say your best bet is to try and do a reverse proxy with Rack middleware (akin to Apache's mod_proxy).
A quick Google search revealed this gem ( https://github.com/jaswope/rack-reverse-proxy ), but the author mentions that it's probably not production-ready. Having a Rack middleware proxy should allow you to forward your subdomain yourdomain.com/blog to another website your-phpfog-account.com/wordpress-installation.
As far as I can tell you can't access the Apache config file with heroku if you could you could use a Rewrite rule.
If you choose not to use heroku you can always do what I detail below.. However if you're not using heroku you could just as easily extract wordpress to the /public/ rails folder and once again use a rewrite rule to get apache to handle the blog requests.
In your apache configuration you'll need to add.
RewriteRule ^/blog/?(.*)$ http://somedomain.com/~user/blog/$1 [P,NC,QSA,L]
It will redirect all requests to /blog/ to the other server.
Source: http://www.igvita.com/2007/07/04/integrating-wordpress-and-rails/
In addition to jplewickeless' answer, I ended up writing custom Rack middelware to replace absolute urls and other paths at the side of the reverse proxy. This guide will get you started on that:
http://railscasts.com/episodes/151-rack-middleware
This is a weird one I know. I'm trying to tie together two Rails applications, a v3 and a v2.3.5
I want them to share the same domain, and in order to do that without changing the URLs in the older app, I'm trying to find a way to override the Rails router.
I want the newer app living at the root of the domain, and the older one under several directories. For example:
/ => app1 # v3
/users => app1
/employees => app2 # v2.3.5
/payrolls => app2
So, since app1 lives at root and I'm using Passenger, I only have to create symlinks in the public folder of app1 to the public folder of app2, like so:
app1/public/employees => app2/public
app1/public/payrolls => app2/public
And then I add RailsBaseURI /employees and RailsBaseURI /payrolls to Apache's config.
With that I can make old URLs of app2 work, but inside the app, the links point to a prefix. For example, /employees/1, /employees/employees/1, /payrolls/employees/1 all work, but links in the app point to /employees/employees/1 and /payrolls/employees/1 depending on which prefix I'm currently on.
So, I need to remove that prefix from the links so only the old URLs work.
I need to do this in order to release the newer app. In time I'll upgrade the older one to v3 and work directly on this issue, but right now any hack is ok just to make it work.
I don't expect a solution, but if you can point me in the right direction on where to look in Rails source, or maybe a simpler approach I'm not seeing, I'd be very grateful.
Turns out it's pretty easy just by overriding url_for in the ApplicationHelper like so:
def url_for(options = {})
original = super(options)
# I tried this in order to improve performance:
return original unless original.starts_with?('/employees/employees')
original.gsub('/employees/employees', '/employees')
end
However, this caused intermittent errors in the app that I wasn't able to pinpoint. I suppose it's because of the performance hit.
So in the end I was forced to use a different domain for the newer apps.
I'm not really sure if that's possible to use 2 different versions of rails on your routes, but another way to do that is using haproxy with 2 different servers.
# In haproxy.conf:
frontend rails
bind *:80
acl rails2 hdr_host(end) -i employees.mydomain.com
acl rails3 hdr_host(end) -i mydomain.com
use_backend rails2_server if rails2
use_backend rails3_server if rails3
default_backend rails3_server
backend rails2_server
server myrails2_server 192.168.1.1:3000 check
backend rails3_server
server myrails3_server 192.168.1.1:3001 check
Then point your DNS A record of mydomain.com to your haproxy IP and point employees.mydomain.com to mydomain.com/employees.
To test it out, you can add the IP address of your haproxy server and mydomain.com to your /etc/hosts file
I've read up on how to use config.action_controller.relative_url_root to set a sub uri in rails and I plan to set my site to www.mydomain.com/mysub_uri.
What I would like thought is for www.mydomain.com to redirect automatically to www.mydoamin.com/mysub_uri.
How do I go about doing this? I am using rails, apache, and phusion.
Thanks!
You could do this with an Apache rewrite (completely independent of Rails). Check the docs here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Let me start by saying I have never deployed a Rails app before.
I have a domain with a main site ran by PHP, let's call it http://www.example.com/.
I have began developing for Rails recently, and I'd like to host the new application I created on http://www.example.com/myapp while still keeping the original site intact.
The main site is hosted on Godaddy.com, but in my understanding they do not support rails well (my application is written in Rails 2.3.5). With that being said, I decided to host my rails app on Dreamhost.com.
So I have two questions: how do I deploy a rails app in a 'folder' on the main domain that actually links to dreamhost. Second, where do I get started with deploying the app?
Thank you!
Personally, I would setup a subdomain on dreamhost: http://myapp.example.com/
Then if you want people to be able to access it via http://www.example.com/myapp, put an .htaccess redirect on your godaddy site:
redirect 301 /myapp/ http://myapp.example.com/
Information on deploying Ruby on Rails on dreamhost's wiki:
http://wiki.dreamhost.com/index.php/Ruby_on_Rails