I have a Ruby on Rails application and a WordPress blog hosted on separate EC2 instances.
I’m trying to make the WordPress blog to act like a subfolder of the Rails application (example.com/blog instead of blog.example.com) for better SEO
- The Rails application can be accessed through http and https (http is redirecting to https)
https://www.nginx.com/resources/admin-guide/reverse-proxy/
I tried using nginx reverse proxy function and I think it’s my best option right now but my attempt was unsuccessful.
- The main page of the blog opens as expected (example.com/blog) but
without css. - A URL with arguements (example.com/blog/args) redirects me back to
the Rails application (example.com/args)
I set the desired blog url in wp-config.php as the following:
define('WP_SITEURL', 'https://www.example.com/blog');
define('WP_HOME', 'https://www.example.com/blog');
This is the nginx configuration I use:
location ^~ /blog {
proxy_pass http://<<BLOGIP>>/blog;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
- https://github.com/waterlink/rack-reverse-proxy
I also tried the
rack-reverse-proxy gem but got the same result
It’s really important for the Rails application and the WordPress blog to stay separated for auto-scaling, redundancy and deployment purposes.
If there’s another way achieving this, I’m open to suggestions.
3
Answers
Solved with Tarun Lalwani's help
Wordpress should be accessable from
nginx config on example.com
added this to wp-config.php
changed the url
As an alternative solution, you could use AWS CDN CloudFront and have multiple origins. One origin for your site and other for the blog. (separated so you can scale them apart)
For setting up WordPress you could follow this post: http://www.danneh.org/2015/04/setting-wordpress-amazon-cloudfront/
Within your CloudFront Distribution the Behaviors, the
Path Pattern
may look like this:Within the CDN you could do the “http to https” besides also only allowing traffic from CloudFront if required.
Your Nginx conf regarding the
location
may look like this:The
/blog
is because CloudFront won’t remove thePath Patterns
so all request to your origins will be prefixed with/blog
Now that you have your blog working at
http://<blogip>/blog
you need fix few more thingsAlso add below to your
wp-config.php