我正在尝试在我的rails应用程序的子目录blog
中运行wordpress,我将此nginx配置用作:
server {
listen 80 default_server;
passenger_ruby /usr/local/bin/ruby;
passenger_enabled on;
rails_env production;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
root /var/www/mydomain/current/public;
location /blog {
root /var/www/example/current;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
如果我在https://example.com
上访问Rails应用,则可以正常加载
如果我访问https://example.com/blog
的wordpress前端,则加载正常
如果我通过https://example.com/blog/wp-admin
访问wordpress管理员,则会得到以下结果:
mydomain.com redirected you too many times.
我的文件夹如下:
/rails_app/
/rails_app/blog/
/rails_app/blog/wp-admin/
其中blog
目录包含wordpress文件
有什么主意吗?
修改
在使用nginx将wordpress放入rails子目录之前,我曾做过尝试,这是我的config/routes.rb
match '/blog', :controller=>'wordpress', :via => [:get], :action=>'fetch'
match '/blog/:slug', :controller=>'wordpress', :via => [:get], :action=>'fetch'
答案 0 :(得分:0)
我能够重现该问题,并通过在wp-config.php中添加以下代码来解决该问题。
if ( 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443';
}