Nginx反向代理从Rails到Wordpress [英] nginx reverse proxy from rails to wordpress
问题描述
我在单独的EC2实例上托管了Ruby on Rails应用程序和Wordpress博客.
I have a Ruby on Rails application and a Wordpress blog hosted on separate EC2 instances.
我正在尝试使Wordpress博客充当Rails应用程序的子文件夹(example.com/blog而不是blog.example.com),以获得更好的SEO
- 可以通过http和https(http重定向到https)访问Rails应用程序
https://www.nginx.com/resources/admin-指南/反向代理/
我尝试使用nginx反向代理功能,现在我认为这是我最好的选择,但是我的尝试没有成功.
I tried using nginx reverse proxy function and I think it's my best option right now but my attempt was unsuccessful.
- 博客的主页按预期方式打开(example.com/blog),但 没有CSS.
- 带有争论的网址(example.com/blog/args)将我重定向回 Rails应用程序(example.com/args)
- 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)
我在wp-config.php中将所需的博客URL设置为以下内容:
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');
这是我使用的Nginx配置:
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
我也尝试过 机架反向代理宝石,但结果相同 - https://github.com/waterlink/rack-reverse-proxy
I also tried the rack-reverse-proxy gem but got the same result
对于Rails应用程序和Wordpress博客,为了自动缩放,冗余和部署目的而保持分离非常重要.
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.
推荐答案
现在,您的博客在http://<blogip>/blog
工作,您需要再解决几件事
Now that you have your blog working at http://<blogip>/blog
you need fix few more things
location ^~ /blog {
proxy_pass http://<<BLOG_IP>>/blog;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http://<ip>/ https://$host/;
proxy_cookie_domain <ip> $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
也将以下内容添加到您的wp-config.php
Also add below to your wp-config.php
define('FORCE_SSL_ADMIN', true);
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
这篇关于Nginx反向代理从Rails到Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!