promoted | KFZ-Versicherung-trotz-Schufa.de
Kfz-Versicherung trotz Schufa-Eintrag: Ein Portal hilft Betroffenen
Kfz-Versicherung trotz Schufa-Eintrag: Ein Portal hilft Betroffenen
Pressemitteilung von Dipesh Batheja
How to setup a WordPress blog with a Ruby on Rails web app?
07.06.2018
Auto & Verkehr
These days, a great blog alongside its main web app is a must have for any SaaS provider. While Ruby on Rails is best when it comes to building a web app, WordPress is number #1 when it comes to blogging.
Why WordPress on Rails?
A blog can definitely be built using Rails itself. But WordPress is already so well optimised and ready to use in a few clicks, that you don’t need to do code a blog from scratch.
Building your own blog solution, or using some existing gems, might still be the best option if you want an entire Rails integration (login, etc…). Or maybe you particularly enjoy doing it. Or maybe you require a very simple version of a blog. Otherwise, and the vast majority of case, it is just unnecessary additional work. WordPress on Rails is the best solution for these cases.
Best Wordpress + RubyOnRails Setup
Wordpress & Rails don’t usually play nice together. So the best option is host RubyOnRails web app on your root domain and host Wordpress blog on a subdomain.
For example:
A Ruby on Rails app can be hosted on Heroku: https://www.awesomeapp.com
A Wordpress blog can hosted on WPEngine: https://blog.awesomeapp.com
You can obviously host both main and sub-domain on single server as well. Netling's website (https://www.netlingshq.com) and client login is built on RubyOnRails and our blog is running on Wordpress hosted on a single DigitalOcean (https://www.digitalocean.com/) VPS instance managed with Plesk Onyx AdminPanel (https://www.plesk.com/).
However, this is not an ideal situation. For maximum search engine optimisation you want your blog to be accessed as a subdirectory?—?not as a subdomain. So essentially you want to achieve something like this:
A Ruby on Rails app hosted on Heroku: https://www.awesomeapp.com
A Wordpress blog hosted on WPEngine: https://www.awesomeapp.com/blog
This brings us to the main question,
How to host a RubyOnRails app on a root domain and a Wordpess blog on a subdomain and still be able to access blog as a sub-directory?
The answer is, put Wordpress blog behind a reverse proxy!
Setup root domain server hosting RubyOnRails app as reverse proxy to forward all requests made for your blog to subdomain running Wordpress. For example, setup https://www.awesomeapp.io as a reverse proxy to forward any requests made to https://www.awesomeapp.com/blog to https://blog.awesomeapp.com.
Typically, this requires changing configuration of your Apache or NGINX instance, but we will use a handy rails gem to achieve the same results - rack-reverse-proxy (https://github.com/jaswope/rack-reverse-proxy) .
On your Rails app
Add the rack-reverse-proxy (https://github.com/jaswope/rack-reverse-proxy) gem to your gemfile:
gem 'rack-reverse-proxy', :require => 'rack/reverse_proxy'
Then, you need your Rails app to redirect /blog/ to your Wordpress blog on subdomain. Go to config.ru and add the following code:
use Rack::ReverseProxy do
reverse_proxy(/^/blog(/.*)$/, 'https://blog.awesomeapp.com$1', opts = { preserve_host: true })
end
Note: Make sure you don’t have a trailing “/” in your URL. It should be https://blog.awesomeapp.com $1 and not https://blog.awesomeapp.com/ $1
Since the blog is technically hosted at /blog/, we need to forward the /blog requests there (notice the non-trailing slash).
Add to config/routes.rb:
get "/blog", to: redirect('https://www.awesomeapp.com/blog/', status: 301)
On your Wordpress blog
In your wp-config.php add following lines:
/**
* Handle SSL reverse proxy
*/
if ($_SERVER == 'https')
$_SERVER='on';
if (isset($_SERVER)) {
$_SERVER = $_SERVER;
}
$_SERVER = "/blog".$_SERVER;
Conclusion
Voilà, you have your beautiful Wordpress blog alongside your powerful Ruby on Rails app.
Thanks for reading! I will keep it updated and add more relevant info in it as needed. If you need any help in getting this setup, don’t hesitate to tweet me: @netlings (https://twitter.com/netlings).
Bildquelle: Netlings Webworks Pvt. Ltd.
https://www.netlingshq.com
Netlings Webworks Pvt. Ltd.
C-3/1, 2nd Floor, Phase-2, Ashok Vihar 42263490 110052 Delhi
Pressekontakt
https://www.netlingshq.com
Netlings Webworks Pvt. Ltd.
C-3/1, 2nd Floor, Phase-2, Ashok Vihar 42263490 110052 Delhi
Diese Pressemitteilung wurde über PR-Gateway veröffentlicht.
Für den Inhalt der Pressemeldung/News ist allein der Verfasser verantwortlich. Newsfenster.de distanziert sich ausdrücklich von den Inhalten Dritter und macht sich diese nicht zu eigen.
Weitere Artikel in dieser Kategorie
26.11.2024 | Wrightbus
Wrightbus vollzieht Sprung nach Europa
Wrightbus vollzieht Sprung nach Europa
26.11.2024 | TUNAP GmbH & Co. KG
Technologie von Tunap schützt SCR-Systeme effizient vor Kristallablagerungen
Technologie von Tunap schützt SCR-Systeme effizient vor Kristallablagerungen
25.11.2024 | NGO Ebner Rita
Geschwindigkeitsbegrenzung 70 km/h jetzt bald einführen
Geschwindigkeitsbegrenzung 70 km/h jetzt bald einführen
22.11.2024 | Rechtsanwaltskanzlei Dr. Schulte
Betrug im Oldtimerrecht: Die Bedeutung von Matching Numbers
Betrug im Oldtimerrecht: Die Bedeutung von Matching Numbers
22.11.2024 | EVUM Motors GmbH
Kosten senken, nachhaltig wachsen: Unternehmen profitieren vom Evum
Kosten senken, nachhaltig wachsen: Unternehmen profitieren vom Evum